blob: 7b3ecd0b3bf5e6787c7dcff339e56c10d43e6efb [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"
Karl Schimpf2e7daef2015-01-09 13:04:13 -080017#include "IceTypes.h"
Antonio Maioranoca8a16e2020-11-10 16:56:20 -050018#include "PNaClTranslator.h"
Karl Schimpf2e7daef2015-01-09 13:04:13 -080019
20namespace IceTest {
21
Karl Schimpfd8b32892015-04-16 15:47:25 -070022void IceTest::SubzeroBitcodeMunger::resetMungeFlags() {
Karl Schimpfd4699942016-04-02 09:55:31 -070023 Ice::ClFlags::Flags.setAllowErrorRecovery(true);
24 Ice::ClFlags::Flags.setDisableTranslation(false);
25 Ice::ClFlags::Flags.setGenerateUnitTestMessages(true);
26 Ice::ClFlags::Flags.setOptLevel(Ice::Opt_m1);
27 Ice::ClFlags::Flags.setOutFileType(Ice::FT_Iasm);
28 Ice::ClFlags::Flags.setTargetArch(Ice::Target_X8632);
29 Ice::ClFlags::Flags.setNumTranslationThreads(0);
30 Ice::ClFlags::Flags.setParseParallel(false);
Karl Schimpfd8b32892015-04-16 15:47:25 -070031}
32
Karl Schimpfcbb1d3d2015-06-08 09:25:15 -070033bool IceTest::SubzeroBitcodeMunger::runTest(const uint64_t Munges[],
John Porto8eefffa2015-06-11 15:14:37 -070034 size_t MungeSize,
35 bool DisableTranslation) {
Karl Schimpfd8b32892015-04-16 15:47:25 -070036 const bool AddHeader = true;
Karl Schimpfcbb1d3d2015-06-08 09:25:15 -070037 setupTest(Munges, MungeSize, AddHeader);
Jim Stichnoth98ba0062016-03-07 09:26:22 -080038 Ice::GlobalContext Ctx(DumpStream, DumpStream, DumpStream, nullptr);
Karl Schimpfe8457a22016-03-31 10:20:23 -070039 Ctx.startWorkerThreads();
Jim Stichnothbbca7542015-02-11 16:08:31 -080040 Ice::PNaClTranslator Translator(&Ctx);
Karl Schimpfcbb1d3d2015-06-08 09:25:15 -070041 const char *BufferName = "Test";
Karl Schimpfd4699942016-04-02 09:55:31 -070042 Ice::ClFlags::Flags.setDisableTranslation(DisableTranslation);
Karl Schimpfcbb1d3d2015-06-08 09:25:15 -070043 Translator.translateBuffer(BufferName, MungedInput.get());
Karl Schimpfe8457a22016-03-31 10:20:23 -070044 Ctx.waitForWorkerThreads();
Karl Schimpf2e7daef2015-01-09 13:04:13 -080045
46 cleanupTest();
Jim Stichnothfa4efea2015-01-27 05:06:03 -080047 return Translator.getErrorStatus().value() == 0;
Karl Schimpf2e7daef2015-01-09 13:04:13 -080048}
49
50} // end of namespace IceTest