mirror of
https://github.com/VirusTotal/yara.git
synced 2026-10-12 02:10:00 +00:00
Simplify test-rules by putting running the all the passes in a single binary.
This makes easier to build the tests with Bazel. Also fix some issues with Bazel configuration.
This commit is contained in:
+3
-9
@@ -60,12 +60,8 @@ test_arena_SOURCES = tests/test-arena.c tests/util.c
|
||||
test_arena_LDADD = libyara/.libs/libyara.a
|
||||
test_atoms_SOURCES = tests/test-atoms.c tests/util.c
|
||||
test_atoms_LDADD = libyara/.libs/libyara.a
|
||||
test_rules_pass_1_SOURCES = tests/test-rules-pass-1.c tests/util.c
|
||||
test_rules_pass_1_LDADD = libyara/.libs/libyara.a
|
||||
test_rules_pass_2_SOURCES = tests/test-rules-pass-2.c tests/util.c
|
||||
test_rules_pass_2_LDADD = libyara/.libs/libyara.a
|
||||
test_rules_pass_3_SOURCES = tests/test-rules-pass-3.c tests/util.c
|
||||
test_rules_pass_3_LDADD = libyara/.libs/libyara.a
|
||||
test_rules_SOURCES = tests/test-rules.c tests/util.c
|
||||
test_rules_LDADD = libyara/.libs/libyara.a
|
||||
test_pe_SOURCES = tests/test-pe.c tests/util.c
|
||||
test_pe_LDADD = libyara/.libs/libyara.a
|
||||
test_elf_SOURCES = tests/test-elf.c tests/util.c
|
||||
@@ -93,9 +89,7 @@ check_PROGRAMS = \
|
||||
test-alignment \
|
||||
test-atoms \
|
||||
test-api \
|
||||
test-rules-pass-1 \
|
||||
test-rules-pass-2 \
|
||||
test-rules-pass-3 \
|
||||
test-rules \
|
||||
test-pe \
|
||||
test-elf \
|
||||
test-version \
|
||||
|
||||
+24
-22
@@ -25,7 +25,6 @@
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
COPTS = [
|
||||
"-D_GNU_SOURCE",
|
||||
# Tell the compiler we want the C99 standard.
|
||||
@@ -48,30 +47,30 @@ cc_test(
|
||||
name = "test_alignment",
|
||||
srcs = ["test-alignment.c"],
|
||||
copts = COPTS,
|
||||
linkstatic = True,
|
||||
deps = ["@//:libyara"],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "test_arena",
|
||||
srcs = ["test-arena.c"],
|
||||
copts = COPTS,
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "test_atoms",
|
||||
srcs = ["test-atoms.c"],
|
||||
copts = COPTS,
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
@@ -87,12 +86,12 @@ cc_test(
|
||||
"data/xorwide.out",
|
||||
"data/xorwideandascii.out",
|
||||
],
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":blob",
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
@@ -102,76 +101,79 @@ cc_test(
|
||||
data = [
|
||||
"data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885",
|
||||
"data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885.upx",
|
||||
"data/mtxex.dll",
|
||||
"data/mtxex_modified_rsrc_rva.dll",
|
||||
"data/tiny",
|
||||
"data/tiny-idata-51ff",
|
||||
"data/tiny-idata-5200",
|
||||
"data/tiny-overlay",
|
||||
"data/weird_rich",
|
||||
"data/mtxex.dll",
|
||||
"data/mtxex_modified_rsrc_rva.dll",
|
||||
],
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "test_elf",
|
||||
srcs = ["test-elf.c"],
|
||||
copts = COPTS,
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":blob",
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "test_api",
|
||||
srcs = ["test-api.c"],
|
||||
data = ["data/baz.yar"],
|
||||
copts = COPTS,
|
||||
data = [
|
||||
"data/baz.yar",
|
||||
"data/x.txt",
|
||||
],
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "test_bitmask",
|
||||
srcs = ["test-bitmask.c"],
|
||||
copts = COPTS,
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "test_math",
|
||||
srcs = ["test-math.c"],
|
||||
copts = COPTS,
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "test_stack",
|
||||
srcs = ["test-stack.c"],
|
||||
copts = COPTS,
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
# This test fails when running under ASAN
|
||||
@@ -179,48 +181,48 @@ cc_test(
|
||||
name = "test_exception",
|
||||
srcs = ["test-exception.c"],
|
||||
copts = COPTS,
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "test_macho",
|
||||
srcs = ["test-macho.c"],
|
||||
data = [
|
||||
"data/tiny-universal",
|
||||
"data/tiny-macho",
|
||||
],
|
||||
copts = COPTS,
|
||||
data = [
|
||||
"data/tiny-macho",
|
||||
"data/tiny-universal",
|
||||
],
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":blob",
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "test_dex",
|
||||
srcs = ["test-dex.c"],
|
||||
copts = COPTS,
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":blob",
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "test_re_split",
|
||||
srcs = ["test-re-split.c"],
|
||||
copts = COPTS,
|
||||
linkstatic = True,
|
||||
deps = [
|
||||
":util",
|
||||
"@//:libyara",
|
||||
],
|
||||
linkstatic=True,
|
||||
)
|
||||
|
||||
@@ -29,6 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <yara.h>
|
||||
#include <yara/globals.h>
|
||||
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020. The YARA Authors. All Rights Reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "test-rules.c"
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020. The YARA Authors. All Rights Reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "test-rules.c"
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020. The YARA Authors. All Rights Reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "test-rules.c"
|
||||
+35
-34
@@ -73,12 +73,10 @@ static void test_boolean_operators()
|
||||
assert_false_rule("rule test { condition: false or false }", NULL);
|
||||
|
||||
assert_false_rule(
|
||||
"import \"tests\" rule test { condition: not tests.undefined.i }",
|
||||
NULL);
|
||||
"import \"tests\" rule test { condition: not tests.undefined.i }", NULL);
|
||||
|
||||
assert_false_rule(
|
||||
"import \"tests\" rule test { condition: tests.undefined.i }",
|
||||
NULL);
|
||||
"import \"tests\" rule test { condition: tests.undefined.i }", NULL);
|
||||
|
||||
assert_false_rule(
|
||||
"import \"tests\" rule test { condition: tests.undefined.i and true }",
|
||||
@@ -1811,7 +1809,7 @@ void test_re()
|
||||
"mississippi\tmississippi.mississippi\nmississippi" TEXT_1024_BYTES);
|
||||
|
||||
assert_true_rule(
|
||||
"rule test { strings: $a = /mississippi.*mississippi$/s condition: $a }",
|
||||
"rule test { strings: $a = /mississippi.*mississippi$/s condition: $a}",
|
||||
TEXT_1024_BYTES "mississippi\tmississippi.mississippi\nmississippi");
|
||||
|
||||
assert_false_rule(
|
||||
@@ -2115,8 +2113,8 @@ void test_re()
|
||||
assert_false_regexp("^abc$", "aabc");
|
||||
assert_false_regexp("abc^", "abc");
|
||||
assert_false_regexp("ab^c", "abc");
|
||||
assert_false_regexp("a^bcdef", "abcdef")
|
||||
assert_true_regexp("abc$", "aabc", "abc");
|
||||
assert_false_regexp("a^bcdef", "abcdef");
|
||||
assert_true_regexp("abc$", "aabc", "abc");
|
||||
assert_false_regexp("$abc", "abc");
|
||||
assert_true_regexp("(a|a$)bcd", "abcd", "abcd");
|
||||
assert_false_regexp("(a$|a$)bcd", "abcd");
|
||||
@@ -2148,16 +2146,20 @@ void test_re()
|
||||
"(ba{4}){4,10}",
|
||||
"baaaabaaaabaaaabaaaabaaaa",
|
||||
"baaaabaaaabaaaabaaaabaaaa");
|
||||
|
||||
assert_true_regexp(
|
||||
"(ba{2}a{2}){5,10}",
|
||||
"baaaabaaaabaaaabaaaabaaaa",
|
||||
"baaaabaaaabaaaabaaaabaaaa");
|
||||
|
||||
assert_true_regexp(
|
||||
"(ba{3}){4,10}", "baaabaaabaaabaaabaaa", "baaabaaabaaabaaabaaa");
|
||||
|
||||
assert_true_regexp(
|
||||
"(ba{4}){5,10}",
|
||||
"baaaabaaaabaaaabaaaabaaaa",
|
||||
"baaaabaaaabaaaabaaaabaaaa");
|
||||
|
||||
assert_false_regexp("(ba{4}){4,10}", "baaaabaaaabaaaa");
|
||||
|
||||
// Test for integer overflow in repeat interval
|
||||
@@ -2945,9 +2947,9 @@ void test_performance_warnings()
|
||||
|
||||
assert_no_warnings("rule test { \
|
||||
strings: $a = { 01 02 03 } \
|
||||
condition: $a }")
|
||||
condition: $a }");
|
||||
|
||||
assert_no_warnings("rule test { \
|
||||
assert_no_warnings("rule test { \
|
||||
strings: $a = { 20 01 02 } \
|
||||
condition: $a }");
|
||||
|
||||
@@ -2991,27 +2993,8 @@ void test_performance_warnings()
|
||||
YR_DEBUG_FPRINTF(1, stderr, "} // %s()\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
static void test_pass(int pass)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
YR_DEBUG_INITIALIZE();
|
||||
YR_DEBUG_FPRINTF(1, stderr, "+ %s() { // in %s\n", __FUNCTION__, argv[0]);
|
||||
|
||||
chdir_if_env_top_srcdir();
|
||||
|
||||
yr_initialize();
|
||||
|
||||
assert_true_expr(strlen(TEXT_1024_BYTES) == 1024);
|
||||
|
||||
// e.g. ./test-rules-pass-1 or test-rules-pass-1.exe
|
||||
char* test_rules_pass = strstr(argv[0], "test-rules-pass-");
|
||||
assert(test_rules_pass != NULL);
|
||||
|
||||
int pass;
|
||||
|
||||
assert(1 == sscanf(test_rules_pass, "test-rules-pass-%d", &pass));
|
||||
|
||||
switch (pass)
|
||||
{
|
||||
case 1:
|
||||
@@ -3026,8 +3009,8 @@ int main(int argc, char** argv)
|
||||
break;
|
||||
case 3:
|
||||
// Come here to test with test libyara iterator which is:
|
||||
// Like default libyara iterator, plus records block stats, plus splits into
|
||||
// multiple blocks:
|
||||
// Like default libyara iterator, plus records block stats, plus splits
|
||||
// into multiple blocks:
|
||||
matches_blob_uses_default_iterator = 0;
|
||||
// "Actually, a single block will contain the whole file's content in most
|
||||
// cases, but you can't rely on that while writing your code. For very big
|
||||
@@ -3113,10 +3096,28 @@ int main(int argc, char** argv)
|
||||
yr_test_count_get_block);
|
||||
}
|
||||
|
||||
YR_DEBUG_FPRINTF(1, stderr, "} // %s()\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
YR_DEBUG_INITIALIZE();
|
||||
YR_DEBUG_FPRINTF(1, stderr, "+ %s() { \n", __FUNCTION__);
|
||||
|
||||
chdir_if_env_top_srcdir();
|
||||
yr_initialize();
|
||||
|
||||
assert_true_expr(strlen(TEXT_1024_BYTES) == 1024);
|
||||
|
||||
for (int i = 1; i <= 3; i++)
|
||||
{
|
||||
printf("--- PASS %d ---\n", i);
|
||||
test_pass(i);
|
||||
}
|
||||
|
||||
yr_finalize();
|
||||
|
||||
YR_DEBUG_FPRINTF(
|
||||
1, stderr, "} = %d // %s() in %s\n", result, __FUNCTION__, argv[0]);
|
||||
YR_DEBUG_FPRINTF(1, stderr, "} // %s()\n", __FUNCTION__);
|
||||
|
||||
return result;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-2
@@ -194,8 +194,7 @@ static YR_MEMORY_BLOCK* _yr_test_multi_block_get_next_block(
|
||||
"- %s() {} = %p // "
|
||||
".base=(0x%" PRIx64 " or %" PRId64 ") of "
|
||||
"(0x%" PRIx64 " or %" PRIu64 ") .size=%" PRIu64
|
||||
", both including %" PRId64
|
||||
" block overlap%s\n",
|
||||
", both including %" PRId64 " block overlap%s\n",
|
||||
__FUNCTION__,
|
||||
result,
|
||||
context->current_block.base,
|
||||
|
||||
Reference in New Issue
Block a user