blob: e554300835d853729b662f5eb70304b0fcce3a30 [file] [log] [blame]
Karl Schimpf2e7daef2015-01-09 13:04:13 -08001//===- BitcodeMunge.cpp - Subzero Bitcode Munger ----------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Test harness for testing malformed bitcode files in Subzero.
11//
12//===----------------------------------------------------------------------===//
13
14#include "BitcodeMunge.h"
15#include "IceCfg.h"
16#include "IceClFlags.h"
17#include "PNaClTranslator.h"
18#include "IceTypes.h"
19
20namespace IceTest {
21
Karl Schimpfd8b32892015-04-16 15:47:25 -070022void IceTest::SubzeroBitcodeMunger::resetMungeFlags() {
Karl Schimpfdf80eb82015-02-09 14:20:22 -080023 Flags.setAllowErrorRecovery(true);
24 Flags.setGenerateUnitTestMessages(true);
Jan Voung1f47ad02015-03-20 15:01:26 -070025 Flags.setOptLevel(Ice::Opt_m1);
Jim Stichnothd442e7e2015-02-12 14:01:48 -080026 Flags.setOutFileType(Ice::FT_Iasm);
Jan Voung1f47ad02015-03-20 15:01:26 -070027 Flags.setTargetArch(Ice::Target_X8632);
28 Flags.setVerbose(Ice::IceV_Instructions);
Karl Schimpfd8b32892015-04-16 15:47:25 -070029}
30
Karl Schimpfcbb1d3d2015-06-08 09:25:15 -070031bool IceTest::SubzeroBitcodeMunger::runTest(const uint64_t Munges[],
John Porto8eefffa2015-06-11 15:14:37 -070032 size_t MungeSize,
33 bool DisableTranslation) {
Karl Schimpfd8b32892015-04-16 15:47:25 -070034 const bool AddHeader = true;
Karl Schimpfcbb1d3d2015-06-08 09:25:15 -070035 setupTest(Munges, MungeSize, AddHeader);
Karl Schimpf2f67b922015-04-22 15:20:16 -070036 Ice::GlobalContext Ctx(DumpStream, DumpStream, DumpStream, nullptr, Flags);
Jim Stichnothbbca7542015-02-11 16:08:31 -080037 Ice::PNaClTranslator Translator(&Ctx);
Karl Schimpfcbb1d3d2015-06-08 09:25:15 -070038 const char *BufferName = "Test";
John Porto8eefffa2015-06-11 15:14:37 -070039 Flags.setDisableTranslation(DisableTranslation);
Karl Schimpfcbb1d3d2015-06-08 09:25:15 -070040 Translator.translateBuffer(BufferName, MungedInput.get());
Karl Schimpf2e7daef2015-01-09 13:04:13 -080041
42 cleanupTest();
Jim Stichnothfa4efea2015-01-27 05:06:03 -080043 return Translator.getErrorStatus().value() == 0;
Karl Schimpf2e7daef2015-01-09 13:04:13 -080044}
45
46} // end of namespace IceTest