diff --git a/testing/btest/Baseline/spicy.spicy-dump/output b/testing/btest/Baseline/spicy.spicy-dump/output new file mode 100644 index 0000000000..01a459395c --- /dev/null +++ b/testing/btest/Baseline/spicy.spicy-dump/output @@ -0,0 +1,10 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +test::X { + xs: [ + 11 + 22 + 33 + 44 + 55 + ] +} diff --git a/testing/btest/Baseline/spicy.spicyz-aot/output b/testing/btest/Baseline/spicy.spicyz-aot/output new file mode 100644 index 0000000000..e7ad0949ae --- /dev/null +++ b/testing/btest/Baseline/spicy.spicyz-aot/output @@ -0,0 +1,5 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +8, [$data=[b"POST /post HTTP/1.1", b"User-Agent: curl/7.29.0", b"Host: httpbin.org", b"Accept: */*", b"Content-Length: 11", b"Content-Type: application/x-www-form-urlencoded", b"", b"hello world"]] +Event:, [POST /post HTTP/1.1, User-Agent: curl/7.29.0, Host: httpbin.org, Accept: */*, Content-Length: 11, Content-Type: application/x-www-form-urlencoded, , hello world] +8, [$data=[b"HTTP/1.1 200 OK", b"Server: gunicorn/0.16.1", b"Date: Tue, 19 Mar 2013 16:05:11 GMT", b"Content-Type: application/json", b"Content-Length: 366", b"Connection: close", b"", b"{\x0a \"origin\": \"10.142.133.148\",\x0a \"files\": {},\x0a \"form\": null,\x0a \"url\": \"http://httpbin.org/post\",\x0a \"args\": {},\x0a \"headers\": {\x0a \"Content-Length\": \"11\",\x0a \"Connection\": \"close\",\x0a \"Accept\": \"*/*\",\x0a \"User-Agent\": \"curl/7.29.0\",\x0a \"Host\": \"httpbin.org\",\x0a \"Content-Type\": \"application/x-www-form-urlencoded\"\x0a },\x0a \"json\": null,\x0a \"data\": \"hello world\"\x0a}"]] +Event:, [HTTP/1.1 200 OK, Server: gunicorn/0.16.1, Date: Tue, 19 Mar 2013 16:05:11 GMT, Content-Type: application/json, Content-Length: 366, Connection: close, , {\x0a "origin": "10.142.133.148",\x0a "files": {},\x0a "form": null,\x0a "url": "http://httpbin.org/post",\x0a "args": {},\x0a "headers": {\x0a "Content-Length": "11",\x0a "Connection": "close",\x0a "Accept": "*/*",\x0a "User-Agent": "curl/7.29.0",\x0a "Host": "httpbin.org",\x0a "Content-Type": "application/x-www-form-urlencoded"\x0a },\x0a "json": null,\x0a "data": "hello world"\x0a}] diff --git a/testing/btest/Baseline/spicy.spicyz-jit/output b/testing/btest/Baseline/spicy.spicyz-jit/output new file mode 100644 index 0000000000..e7ad0949ae --- /dev/null +++ b/testing/btest/Baseline/spicy.spicyz-jit/output @@ -0,0 +1,5 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +8, [$data=[b"POST /post HTTP/1.1", b"User-Agent: curl/7.29.0", b"Host: httpbin.org", b"Accept: */*", b"Content-Length: 11", b"Content-Type: application/x-www-form-urlencoded", b"", b"hello world"]] +Event:, [POST /post HTTP/1.1, User-Agent: curl/7.29.0, Host: httpbin.org, Accept: */*, Content-Length: 11, Content-Type: application/x-www-form-urlencoded, , hello world] +8, [$data=[b"HTTP/1.1 200 OK", b"Server: gunicorn/0.16.1", b"Date: Tue, 19 Mar 2013 16:05:11 GMT", b"Content-Type: application/json", b"Content-Length: 366", b"Connection: close", b"", b"{\x0a \"origin\": \"10.142.133.148\",\x0a \"files\": {},\x0a \"form\": null,\x0a \"url\": \"http://httpbin.org/post\",\x0a \"args\": {},\x0a \"headers\": {\x0a \"Content-Length\": \"11\",\x0a \"Connection\": \"close\",\x0a \"Accept\": \"*/*\",\x0a \"User-Agent\": \"curl/7.29.0\",\x0a \"Host\": \"httpbin.org\",\x0a \"Content-Type\": \"application/x-www-form-urlencoded\"\x0a },\x0a \"json\": null,\x0a \"data\": \"hello world\"\x0a}"]] +Event:, [HTTP/1.1 200 OK, Server: gunicorn/0.16.1, Date: Tue, 19 Mar 2013 16:05:11 GMT, Content-Type: application/json, Content-Length: 366, Connection: close, , {\x0a "origin": "10.142.133.148",\x0a "files": {},\x0a "form": null,\x0a "url": "http://httpbin.org/post",\x0a "args": {},\x0a "headers": {\x0a "Content-Length": "11",\x0a "Connection": "close",\x0a "Accept": "*/*",\x0a "User-Agent": "curl/7.29.0",\x0a "Host": "httpbin.org",\x0a "Content-Type": "application/x-www-form-urlencoded"\x0a },\x0a "json": null,\x0a "data": "hello world"\x0a}] diff --git a/testing/btest/btest.cfg b/testing/btest/btest.cfg index 7e5eedd02a..ad2ac12d6b 100644 --- a/testing/btest/btest.cfg +++ b/testing/btest/btest.cfg @@ -1,5 +1,5 @@ [btest] -TestDirs = doc bifs language core scripts coverage signatures plugins broker supervisor telemetry +TestDirs = doc bifs language core scripts coverage signatures plugins broker spicy supervisor telemetry TmpDir = %(testbase)s/.tmp BaselineDir = %(testbase)s/Baseline IgnoreDirs = .svn CVS .tmp @@ -32,6 +32,8 @@ ZEEK_DISABLE_ZEEKYGEN=1 ZEEK_ALLOW_INIT_ERRORS=1 ZEEK_SUPERVISOR_NO_SIGKILL=1 UBSAN_OPTIONS=print_stacktrace=1 +SPICY_PATH=`bash -c %(testbase)s/../../build/spicy-path` +HILTI_CXX_INCLUDE_DIRS=`bash -c %(testbase)s/../../build/hilti-cxx-include-dirs` [environment-AST-dup] # Environment for testing AST duplication functionality, which is diff --git a/testing/btest/spicy/spicy-dump.spicy b/testing/btest/spicy/spicy-dump.spicy new file mode 100644 index 0000000000..40f849354b --- /dev/null +++ b/testing/btest/spicy/spicy-dump.spicy @@ -0,0 +1,11 @@ +# @TEST-DOC: Smoke test for a bundled Spicy. +# +# @TEST-REQUIRES: $SCRIPTS/have-spicy +# @TEST-EXEC: printf 12345 | ${BUILD}/auxil/spicy/spicy/bin/spicy-dump -d %INPUT >output 2>&1 +# @TEST-EXEC: btest-diff output + +module test; + +public type X = unit { + xs: (bytes &size=1 &convert=$$.to_int()*11)[]; +}; diff --git a/testing/btest/spicy/spicyz-aot.test b/testing/btest/spicy/spicyz-aot.test new file mode 100644 index 0000000000..7abbf30745 --- /dev/null +++ b/testing/btest/spicy/spicyz-aot.test @@ -0,0 +1,37 @@ +# @TEST-DOC: Smoke test for a custom ahead-of-time compiled Spicy analyzer hooked into Zeek. +# +# @TEST-REQUIRES: $SCRIPTS/have-spicy +# @TEST-EXEC: ${BUILD}/src/builtin-plugins/spicy-plugin/bin/spicyz test.spicy test.evt -o test.hlto +# @TEST-EXEC: zeek -NN test.hlto | grep -q ANALYZER_SPICY_TEST +# @TEST-EXEC: zeek -r ${TRACES}/http/post.trace test.zeek test.hlto "Spicy::enable_print = T;" >>output 2>&1 +# @TEST-EXEC: btest-diff output + +# @TEST-START-FILE test.spicy +module test; + +import zeek; + +public type Dummy = unit { + # Consume all data. We split data into lines and log the number of lines and the lines when done. + data: bytes &eod &convert=$$.split(b"\r\n"); + + on %done { print |self.data|, self; } +}; +# @TEST-END-FILE + +# @TEST-START-FILE test.evt +protocol analyzer spicy::Test over TCP: + parse with test::Dummy, + port 80/tcp; + +on test::Dummy -> event test::dummy(self.data); +# @TEST-END-FILE + +# @TEST-START-FILE test.zeek +module test; + +event test::dummy(data: vector of string) +{ + print "Event:", data; +} +# @TEST-END-FILE diff --git a/testing/btest/spicy/spicyz-jit.test b/testing/btest/spicy/spicyz-jit.test new file mode 100644 index 0000000000..a462dd0625 --- /dev/null +++ b/testing/btest/spicy/spicyz-jit.test @@ -0,0 +1,37 @@ +# @TEST-DOC: Smoke test for a custom Spicy analyzer hooked into Zeek with JIT via Zeek itself. +# +# @TEST-REQUIRES: $SCRIPTS/have-spicy +# @TEST-EXEC: ${BUILD}/src/builtin-plugins/spicy-plugin/bin/spicyz test.spicy test.evt -o test.hlto +# @TEST-EXEC: zeek -NN test.hlto | grep -q ANALYZER_SPICY_TEST +# @TEST-EXEC: zeek -r ${TRACES}/http/post.trace test.zeek test.spicy test.evt "Spicy::enable_print = T;" >>output 2>&1 +# @TEST-EXEC: btest-diff output + +# @TEST-START-FILE test.spicy +module test; + +import zeek; + +public type Dummy = unit { + # Consume all data. We split data into lines and log the number of lines and the lines when done. + data: bytes &eod &convert=$$.split(b"\r\n"); + + on %done { print |self.data|, self; } +}; +# @TEST-END-FILE + +# @TEST-START-FILE test.evt +protocol analyzer spicy::Test over TCP: + parse with test::Dummy, + port 80/tcp; + +on test::Dummy -> event test::dummy(self.data); +# @TEST-END-FILE + +# @TEST-START-FILE test.zeek +module test; + +event test::dummy(data: vector of string) +{ + print "Event:", data; +} +# @TEST-END-FILE diff --git a/testing/scripts/have-spicy b/testing/scripts/have-spicy new file mode 100755 index 0000000000..d520e7438d --- /dev/null +++ b/testing/scripts/have-spicy @@ -0,0 +1,6 @@ +#!/bin/sh +if grep -q "DISABLE_SPICY:BOOL=true" "${BUILD}"/CMakeCache.txt; then + return 1 +else + true +fi