3411775b |
/*
* Unit tests for bytecode functions.
* |
e1cbc270 |
* Copyright (C) 2013-2019 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
* Copyright (C) 2009-2013 Sourcefire, Inc. |
3411775b |
*
* Authors: Török Edvin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <check.h> |
b26d4380 |
#include <fcntl.h> |
a969167b |
#include <errno.h> |
b2e7c931 |
|
3411775b |
#include "../libclamav/clamav.h"
#include "../libclamav/others.h"
#include "../libclamav/bytecode.h"
#include "checks.h" |
6eeadbfe |
#include "../libclamav/dconf.h" |
b63681a5 |
#include "../libclamav/bytecode_priv.h" |
b26d4380 |
#include "../libclamav/pe.h" |
71a5cb43 |
#ifdef CL_THREAD_SAFE
#include <pthread.h>
#endif |
3411775b |
|
b26d4380 |
static void runtest(const char *file, uint64_t expected, int fail, int nojit, |
288057e9 |
const char *infile, struct cli_pe_hook_data *pedata,
struct cli_exe_section *sections, const char *expectedvirname,
int testmode) |
3411775b |
{ |
b26d4380 |
fmap_t *map = NULL; |
3411775b |
int rc;
int fd = open_testfile(file);
FILE *f;
struct cli_bc bc; |
b26d4380 |
cli_ctx cctx; |
3411775b |
struct cli_bc_ctx *ctx; |
d1487222 |
struct cli_all_bc bcs; |
3411775b |
uint64_t v; |
a969167b |
struct cl_engine *engine; |
aadccfd1 |
int fdin = -1; |
62ee12b2 |
char filestr[512]; |
288057e9 |
const char *virname = NULL; |
048a88e6 |
struct cl_scan_options options; |
3411775b |
|
b26d4380 |
memset(&cctx, 0, sizeof(cctx)); |
048a88e6 |
memset(&options, 0, sizeof(struct cl_scan_options));
cctx.options = &options;
cctx.options->general |= CL_SCAN_GENERAL_ALLMATCHES; |
6ad45a29 |
cctx.virname = &virname; |
a969167b |
cctx.engine = engine = cl_engine_new();
fail_unless(!!cctx.engine, "cannot create engine"); |
fc01c647 |
rc = cl_engine_compile(engine);
fail_unless(!rc, "cannot compile engine"); |
288057e9 |
cctx.fmap = cli_calloc(sizeof(fmap_t *), engine->maxreclevel + 2); |
fc01c647 |
fail_unless(!!cctx.fmap, "cannot allocate fmap"); |
b26d4380 |
|
3411775b |
fail_unless(fd >= 0, "retmagic open failed");
f = fdopen(fd, "r");
fail_unless(!!f, "retmagic fdopen failed");
cl_debug();
|
2487a4a3 |
if (!nojit) { |
288057e9 |
rc = cli_bytecode_init(&bcs);
fail_unless(rc == CL_SUCCESS, "cli_bytecode_init failed"); |
2487a4a3 |
} else { |
288057e9 |
bcs.engine = NULL; |
2487a4a3 |
} |
d1487222 |
bcs.all_bcs = &bc; |
288057e9 |
bcs.count = 1; |
d1487222 |
|
54402320 |
rc = cli_bytecode_load(&bc, f, NULL, 1, 0); |
3411775b |
fail_unless(rc == CL_SUCCESS, "cli_bytecode_load failed");
fclose(f);
|
47cee504 |
if (testmode && have_clamjit) |
288057e9 |
engine->bytecode_mode = CL_BYTECODE_MODE_TEST; |
927d0548 |
|
540fc128 |
rc = cli_bytecode_prepare2(engine, &bcs, BYTECODE_ENGINE_MASK); |
6922903a |
fail_unless(rc == CL_SUCCESS, "cli_bytecode_prepare failed");
|
47cee504 |
if (have_clamjit && !nojit && nojit != -1 && !testmode) { |
288057e9 |
fail_unless(bc.state == bc_jit, "preparing for JIT failed"); |
2487a4a3 |
}
|
288057e9 |
ctx = cli_bytecode_context_alloc(); |
e407d32d |
ctx->bytecode_timeout = fail == CL_ETIMEOUT ? 10 : 10000; |
3411775b |
fail_unless(!!ctx, "cli_bytecode_context_alloc failed");
|
a969167b |
ctx->ctx = &cctx; |
b26d4380 |
if (infile) { |
288057e9 |
snprintf(filestr, sizeof(filestr), OBJDIR "/%s", infile);
fdin = open(filestr, O_RDONLY);
if (fdin < 0 && errno == ENOENT)
fdin = open_testfile(infile);
fail_unless(fdin >= 0, "failed to open infile");
map = fmap(fdin, 0, 0);
fail_unless(!!map, "unable to fmap infile");
if (pedata)
ctx->hooks.pedata = pedata;
ctx->sections = sections;
cli_bytecode_context_setfile(ctx, map); |
b26d4380 |
}
|
3411775b |
cli_bytecode_context_setfuncid(ctx, &bc, 0); |
85a25497 |
rc = cli_bytecode_run(&bcs, &bc, ctx); |
646395bb |
fail_unless_fmt(rc == fail, "cli_bytecode_run failed, expected: %u, have: %u\n", |
288057e9 |
fail, rc); |
3411775b |
|
6b67ec6e |
if (rc == CL_SUCCESS) { |
288057e9 |
v = cli_bytecode_context_getresult_int(ctx);
fail_unless_fmt(v == expected, "Invalid return value from bytecode run, expected: %llx, have: %llx\n",
expected, v); |
6b67ec6e |
} |
b26d4380 |
if (infile && expectedvirname) { |
288057e9 |
fail_unless(ctx->virname &&
!strcmp(ctx->virname, expectedvirname),
"Invalid virname, expected: %s\n", expectedvirname); |
b26d4380 |
} |
3411775b |
cli_bytecode_context_destroy(ctx); |
b26d4380 |
if (map) |
288057e9 |
funmap(map); |
3411775b |
cli_bytecode_destroy(&bc); |
d1487222 |
cli_bytecode_done(&bcs); |
fc01c647 |
free(cctx.fmap); |
a969167b |
cl_engine_free(engine); |
aadccfd1 |
if (fdin >= 0) |
288057e9 |
close(fdin); |
3411775b |
}
|
288057e9 |
START_TEST(test_retmagic_jit) |
3411775b |
{ |
2487a4a3 |
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/retmagic.cbc", 0x1234f00d, CL_SUCCESS, 0, NULL, NULL, NULL, NULL, 0); |
213dfdff |
runtest("input/retmagic.cbc", 0x1234f00d, CL_SUCCESS, 0, NULL, NULL, NULL, NULL, 1); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_retmagic_int) |
fa82ce03 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/retmagic.cbc", 0x1234f00d, CL_SUCCESS, 1, NULL, NULL, NULL, NULL, 0); |
3411775b |
}
END_TEST
|
288057e9 |
START_TEST(test_arith_jit) |
3411775b |
{ |
2487a4a3 |
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/arith.cbc", 0xd5555555, CL_SUCCESS, 0, NULL, NULL, NULL, NULL, 0); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_arith_int) |
fa82ce03 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/arith.cbc", 0xd5555555, CL_SUCCESS, 1, NULL, NULL, NULL, NULL, 0); |
3411775b |
}
END_TEST |
cf0cd429 |
|
288057e9 |
START_TEST(test_apicalls_jit) |
cf0cd429 |
{ |
2487a4a3 |
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/apicalls.cbc", 0xf00d, CL_SUCCESS, 0, NULL, NULL, NULL, NULL, 0); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_apicalls_int) |
fa82ce03 |
{ |
d049a2f7 |
runtest("input/apicalls.cbc", 0xf00d, CL_SUCCESS, 1, NULL, NULL, NULL, NULL, 0); |
cf0cd429 |
}
END_TEST
|
288057e9 |
START_TEST(test_apicalls2_jit) |
e6d1fe78 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/apicalls2.cbc", 0xf00d, CL_SUCCESS, 0, NULL, NULL, NULL, NULL, 0); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_apicalls2_int) |
fa82ce03 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/apicalls2.cbc", 0xf00d, CL_SUCCESS, 1, NULL, NULL, NULL, NULL, 0); |
e6d1fe78 |
}
END_TEST
|
288057e9 |
START_TEST(test_div0_jit) |
6b67ec6e |
{ |
2487a4a3 |
cl_init(CL_INIT_DEFAULT); |
6b67ec6e |
/* must not crash on div#0 but catch it */ |
d049a2f7 |
runtest("input/div0.cbc", 0, CL_EBYTECODE, 0, NULL, NULL, NULL, NULL, 0); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_div0_int) |
fa82ce03 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/div0.cbc", 0, CL_EBYTECODE, 1, NULL, NULL, NULL, NULL, 0); |
6b67ec6e |
}
END_TEST |
cf0cd429 |
|
288057e9 |
START_TEST(test_lsig_jit) |
52dd3a6b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/lsig.cbc", 0, 0, 0, NULL, NULL, NULL, NULL, 0); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_lsig_int) |
fa82ce03 |
{ |
d049a2f7 |
runtest("input/lsig.cbc", 0, 0, 1, NULL, NULL, NULL, NULL, 0); |
52dd3a6b |
}
END_TEST
|
288057e9 |
START_TEST(test_inf_jit) |
b63681a5 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/inf.cbc", 0, CL_ETIMEOUT, 0, NULL, NULL, NULL, NULL, 0); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_inf_int) |
fa82ce03 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/inf.cbc", 0, CL_ETIMEOUT, 1, NULL, NULL, NULL, NULL, 0); |
b26d4380 |
}
END_TEST
|
288057e9 |
START_TEST(test_matchwithread_jit) |
b26d4380 |
{
struct cli_exe_section sect;
struct cli_pe_hook_data pedata;
cl_init(CL_INIT_DEFAULT);
memset(&pedata, 0, sizeof(pedata));
pedata.ep = 64; |
d7729040 |
cli_writeint32(&pedata.opt32.ImageBase, 0x400000); |
288057e9 |
pedata.hdr_size = 0x400; |
b26d4380 |
pedata.nsections = 1; |
288057e9 |
sect.rva = 4096;
sect.vsz = 4096;
sect.raw = 0;
sect.rsz = 512;
sect.urva = 4096;
sect.uvsz = 4096;
sect.uraw = 1;
sect.ursz = 512; |
b26d4380 |
runtest("input/matchwithread.cbc", 0, 0, 0, "../test/clam.exe", &pedata, |
288057e9 |
§, "ClamAV-Test-File-detected-via-bytecode", 0); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_matchwithread_int) |
fa82ce03 |
{
struct cli_exe_section sect;
struct cli_pe_hook_data pedata;
cl_init(CL_INIT_DEFAULT);
memset(&pedata, 0, sizeof(pedata));
pedata.ep = 64; |
d7729040 |
cli_writeint32(&pedata.opt32.ImageBase, 0x400000); |
288057e9 |
pedata.hdr_size = 0x400; |
fa82ce03 |
pedata.nsections = 1; |
288057e9 |
sect.rva = 4096;
sect.vsz = 4096;
sect.raw = 0;
sect.rsz = 512;
sect.urva = 4096;
sect.uvsz = 4096;
sect.uraw = 1;
sect.ursz = 512; |
b26d4380 |
runtest("input/matchwithread.cbc", 0, 0, 1, "../test/clam.exe", &pedata, |
288057e9 |
§, "ClamAV-Test-File-detected-via-bytecode", 0); |
b63681a5 |
}
END_TEST
|
288057e9 |
START_TEST(test_pdf_jit) |
48fc8b98 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/pdf.cbc", 0, 0, 0, NULL, NULL, NULL, NULL, 0); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_pdf_int) |
fa82ce03 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/pdf.cbc", 0, 0, 1, NULL, NULL, NULL, NULL, 0); |
48fc8b98 |
}
END_TEST
|
288057e9 |
START_TEST(test_bswap_jit) |
6ea339ae |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/bswap.cbc", 0xbeef, 0, 0, NULL, NULL, NULL, NULL, 0); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_bswap_int) |
fa82ce03 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/bswap.cbc", 0xbeef, 0, 1, NULL, NULL, NULL, NULL, 0); |
6ea339ae |
}
END_TEST
|
288057e9 |
START_TEST(test_inflate_jit) |
fa82ce03 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/inflate.cbc", 0xbeef, 0, 1, NULL, NULL, NULL, NULL, 0); |
fa82ce03 |
}
END_TEST
|
288057e9 |
START_TEST(test_inflate_int) |
778df8c2 |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/inflate.cbc", 0xbeef, 0, 0, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_api_extract_jit) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/api_extract_7.cbc", 0xf00d, 0, 0, "input/apitestfile", NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_api_files_jit) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/api_files_7.cbc", 0xf00d, 0, 0, "input/apitestfile", NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_apicalls2_7_jit) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/apicalls2_7.cbc", 0xf00d, 0, 0, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_apicalls_7_jit) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/apicalls_7.cbc", 0xf00d, 0, 0, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_arith_7_jit) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/arith_7.cbc", 0xd55555dd, CL_SUCCESS, 0, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_debug_jit) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/debug_7.cbc", 0xf00d, 0, 0, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_inf_7_jit) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/inf_7.cbc", 0, CL_ETIMEOUT, 0, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_lsig_7_jit) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/lsig_7.cbc", 0, 0, 0, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_retmagic_7_jit) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/retmagic_7.cbc", 0x1234f00d, CL_SUCCESS, 0, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_testadt_jit) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/testadt_7.cbc", 0xf00d, 0, 0, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_api_extract_int) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/api_extract_7.cbc", 0xf00d, 0, 1, "input/apitestfile", NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_api_files_int) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/api_files_7.cbc", 0xf00d, 0, 1, "input/apitestfile", NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_apicalls2_7_int) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/apicalls2_7.cbc", 0xf00d, 0, 1, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_apicalls_7_int) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/apicalls_7.cbc", 0xf00d, 0, 1, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_arith_7_int) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/arith_7.cbc", 0xd55555dd, CL_SUCCESS, 1, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_debug_int) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/debug_7.cbc", 0xf00d, 0, 1, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_inf_7_int) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/inf_7.cbc", 0, CL_ETIMEOUT, 1, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_lsig_7_int) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/lsig_7.cbc", 0, 0, 1, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_retmagic_7_int) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/retmagic_7.cbc", 0x1234f00d, CL_SUCCESS, 1, NULL, NULL, NULL, NULL, 0); |
a969167b |
}
END_TEST
|
288057e9 |
START_TEST(test_testadt_int) |
a969167b |
{
cl_init(CL_INIT_DEFAULT); |
d049a2f7 |
runtest("input/testadt_7.cbc", 0xf00d, 0, 1, NULL, NULL, NULL, NULL, 0); |
778df8c2 |
}
END_TEST
|
288057e9 |
static void runload(const char *dbname, struct cl_engine *engine, unsigned signoexp) |
1ab57a63 |
{ |
288057e9 |
const char *srcdir = getenv("srcdir"); |
1ab57a63 |
char *str;
unsigned signo = 0;
int rc; |
288057e9 |
if (!srcdir) {
/* when run from automake srcdir is set, but if run manually then not */
srcdir = SRCDIR; |
1ab57a63 |
} |
288057e9 |
str = cli_malloc(strlen(dbname) + strlen(srcdir) + 2); |
1ab57a63 |
fail_unless(!!str, "cli_malloc");
sprintf(str, "%s/%s", srcdir, dbname);
rc = cl_load(str, engine, &signo, CL_DB_STDOPT);
fail_unless_fmt(rc == CL_SUCCESS, "failed to load %s: %s\n", |
288057e9 |
dbname, cl_strerror(rc)); |
1ab57a63 |
fail_unless_fmt(signo == signoexp, "different number of signatures loaded, expected %u, got %u\n", |
288057e9 |
signoexp, signo); |
1ab57a63 |
free(str);
rc = cl_engine_compile(engine);
fail_unless_fmt(rc == CL_SUCCESS, "failed to load %s: %s\n", |
288057e9 |
dbname, cl_strerror(rc)); |
1ab57a63 |
}
|
288057e9 |
START_TEST(test_load_bytecode_jit) |
1ab57a63 |
{
struct cl_engine *engine;
cl_init(CL_INIT_DEFAULT);
engine = cl_engine_new();
fail_unless(!!engine, "failed to create engine\n");
runload("input/bytecode.cvd", engine, 5);
cl_engine_free(engine);
}
END_TEST
|
288057e9 |
START_TEST(test_load_bytecode_int) |
1ab57a63 |
{
struct cl_engine *engine;
cl_init(CL_INIT_DEFAULT); |
288057e9 |
engine = cl_engine_new(); |
1ab57a63 |
engine->dconf->bytecode = BYTECODE_INTERPRETER;
fail_unless(!!engine, "failed to create engine\n");
runload("input/bytecode.cvd", engine, 5);
cl_engine_free(engine);
}
END_TEST
|
5007986f |
#if defined(CL_THREAD_SAFE) && defined(C_LINUX) && ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 4) |
314c415b |
#define DO_BARRIER
#endif
#ifdef DO_BARRIER |
a7cf187a |
static pthread_barrier_t barrier; |
288057e9 |
static void *thread(void *arg) |
a7cf187a |
{
struct cl_engine *engine;
engine = cl_engine_new();
fail_unless(!!engine, "failed to create engine\n");
/* run all cl_load at once, to maximize chance of a crash
* in case of a race condition */
pthread_barrier_wait(&barrier);
runload("input/bytecode.cvd", engine, 5);
cl_engine_free(engine);
return NULL;
}
|
288057e9 |
START_TEST(test_parallel_load) |
a7cf187a |
{
#define N 5
pthread_t threads[N];
unsigned i;
cl_init(CL_INIT_DEFAULT);
pthread_barrier_init(&barrier, NULL, N); |
288057e9 |
for (i = 0; i < N; i++) {
pthread_create(&threads[i], NULL, thread, NULL); |
a7cf187a |
} |
288057e9 |
for (i = 0; i < N; i++) {
pthread_join(threads[i], NULL); |
a7cf187a |
}
/* DB load used to crash due to 'static' variable in cache.c,
* and also due to something wrong in LLVM 2.7.
* Enabled the mutex around codegen in bytecode2llvm.cpp, and this test is
* here to make sure it doesn't crash */
}
END_TEST
#endif
|
3411775b |
Suite *test_bytecode_suite(void)
{ |
288057e9 |
Suite *s = suite_create("bytecode"); |
3411775b |
TCase *tc_cli_arith = tcase_create("arithmetic");
suite_add_tcase(s, tc_cli_arith); |
e407d32d |
tcase_set_timeout(tc_cli_arith, 20); |
fa82ce03 |
tcase_add_test(tc_cli_arith, test_retmagic_jit);
tcase_add_test(tc_cli_arith, test_arith_jit);
tcase_add_test(tc_cli_arith, test_apicalls_jit);
tcase_add_test(tc_cli_arith, test_apicalls2_jit);
tcase_add_test(tc_cli_arith, test_div0_jit);
tcase_add_test(tc_cli_arith, test_lsig_jit);
tcase_add_test(tc_cli_arith, test_inf_jit);
tcase_add_test(tc_cli_arith, test_matchwithread_jit);
tcase_add_test(tc_cli_arith, test_pdf_jit);
tcase_add_test(tc_cli_arith, test_bswap_jit);
tcase_add_test(tc_cli_arith, test_inflate_jit); |
a969167b |
|
fa82ce03 |
tcase_add_test(tc_cli_arith, test_arith_int);
tcase_add_test(tc_cli_arith, test_apicalls_int);
tcase_add_test(tc_cli_arith, test_apicalls2_int);
tcase_add_test(tc_cli_arith, test_div0_int);
tcase_add_test(tc_cli_arith, test_lsig_int);
tcase_add_test(tc_cli_arith, test_inf_int);
tcase_add_test(tc_cli_arith, test_matchwithread_int);
tcase_add_test(tc_cli_arith, test_pdf_int);
tcase_add_test(tc_cli_arith, test_bswap_int);
tcase_add_test(tc_cli_arith, test_inflate_int); |
e4a0f2c9 |
tcase_add_test(tc_cli_arith, test_retmagic_int); |
a969167b |
tcase_add_test(tc_cli_arith, test_api_extract_jit);
tcase_add_test(tc_cli_arith, test_api_files_jit);
tcase_add_test(tc_cli_arith, test_apicalls2_7_jit);
tcase_add_test(tc_cli_arith, test_apicalls_7_jit);
tcase_add_test(tc_cli_arith, test_apicalls_7_jit);
tcase_add_test(tc_cli_arith, test_arith_7_jit);
tcase_add_test(tc_cli_arith, test_debug_jit);
tcase_add_test(tc_cli_arith, test_inf_7_jit);
tcase_add_test(tc_cli_arith, test_lsig_7_jit);
tcase_add_test(tc_cli_arith, test_retmagic_7_jit);
tcase_add_test(tc_cli_arith, test_testadt_jit);
tcase_add_test(tc_cli_arith, test_api_extract_int);
tcase_add_test(tc_cli_arith, test_api_files_int);
tcase_add_test(tc_cli_arith, test_apicalls2_7_int);
tcase_add_test(tc_cli_arith, test_apicalls_7_int);
tcase_add_test(tc_cli_arith, test_apicalls_7_int);
tcase_add_test(tc_cli_arith, test_arith_7_int);
tcase_add_test(tc_cli_arith, test_debug_int);
tcase_add_test(tc_cli_arith, test_inf_7_int);
tcase_add_test(tc_cli_arith, test_lsig_7_int);
tcase_add_test(tc_cli_arith, test_retmagic_int);
tcase_add_test(tc_cli_arith, test_testadt_int);
|
1ab57a63 |
tcase_add_test(tc_cli_arith, test_load_bytecode_jit);
tcase_add_test(tc_cli_arith, test_load_bytecode_int); |
314c415b |
#ifdef DO_BARRIER |
a7cf187a |
tcase_add_test(tc_cli_arith, test_parallel_load);
#endif |
1ab57a63 |
|
3411775b |
return s;
} |