From 2df6d35e3299ecce7975502a007c1ca456f4b8bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Tue, 10 Dec 2019 11:51:43 +0100 Subject: [PATCH] tests: add test cases for blobmsg parsing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Increasing test coverage. Signed-off-by: Petr Å tetiar --- tests/cram/test_blobmsg_parse.t | 65 +++++++++++++++++++++++++++++ tests/test-blobmsg-parse.c | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 tests/cram/test_blobmsg_parse.t create mode 100644 tests/test-blobmsg-parse.c diff --git a/tests/cram/test_blobmsg_parse.t b/tests/cram/test_blobmsg_parse.t new file mode 100644 index 0000000..37e09ce --- /dev/null +++ b/tests/cram/test_blobmsg_parse.t @@ -0,0 +1,65 @@ +check that blobmsg_parse is producing expected results: + + $ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH" + $ export FUZZ_CORPUS="$TESTDIR/../fuzz/corpus" + + $ for blob in $(LC_ALL=C find $FUZZ_CORPUS -type f | sort ); do + > valgrind --quiet --leak-check=full test-blobmsg-parse $blob; \ + > test-blobmsg-parse-san $blob; \ + > done + 71520a5c4b5ca73903216857abbad54a8002d44a: blobmsg_parse: ... (0) + 71520a5c4b5ca73903216857abbad54a8002d44a: blobmsg_parse_array: ... (0) + 71520a5c4b5ca73903216857abbad54a8002d44a: blobmsg_parse: ... (0) + 71520a5c4b5ca73903216857abbad54a8002d44a: blobmsg_parse_array: ... (0) + c1dfd96eea8cc2b62785275bca38ac261256e278: blobmsg_parse: ... (0) + c1dfd96eea8cc2b62785275bca38ac261256e278: blobmsg_parse_array: ... (0) + c1dfd96eea8cc2b62785275bca38ac261256e278: blobmsg_parse: ... (0) + c1dfd96eea8cc2b62785275bca38ac261256e278: blobmsg_parse_array: ... (0) + c42ac1c46f1d4e211c735cc7dfad4ff8391110e9: blobmsg_parse: ... (0) + c42ac1c46f1d4e211c735cc7dfad4ff8391110e9: blobmsg_parse_array: ... (0) + c42ac1c46f1d4e211c735cc7dfad4ff8391110e9: blobmsg_parse: ... (0) + c42ac1c46f1d4e211c735cc7dfad4ff8391110e9: blobmsg_parse_array: ... (0) + crash-1b8fb1be45db3aff7699100f497fb74138f3df4f: blobmsg_parse: ... (0) + crash-1b8fb1be45db3aff7699100f497fb74138f3df4f: blobmsg_parse_array: ... (0) + crash-1b8fb1be45db3aff7699100f497fb74138f3df4f: blobmsg_parse: ... (0) + crash-1b8fb1be45db3aff7699100f497fb74138f3df4f: blobmsg_parse_array: ... (0) + crash-333757b203a44751d3535f24b05f467183a96d09: blobmsg_parse: ... (0) + crash-333757b203a44751d3535f24b05f467183a96d09: blobmsg_parse_array: ... (0) + crash-333757b203a44751d3535f24b05f467183a96d09: blobmsg_parse: ... (0) + crash-333757b203a44751d3535f24b05f467183a96d09: blobmsg_parse_array: ... (0) + crash-4c4d2c3c9ade5da9347534e290305c3b9760f627: blobmsg_parse: ... (0) + crash-4c4d2c3c9ade5da9347534e290305c3b9760f627: blobmsg_parse_array: ... (-1) + crash-4c4d2c3c9ade5da9347534e290305c3b9760f627: blobmsg_parse: ... (0) + crash-4c4d2c3c9ade5da9347534e290305c3b9760f627: blobmsg_parse_array: ... (-1) + crash-5e9937b197c88bf4e7b7ee2612456cad4cb83f5b: blobmsg_parse: ... (0) + crash-5e9937b197c88bf4e7b7ee2612456cad4cb83f5b: blobmsg_parse_array: ... (-1) + crash-5e9937b197c88bf4e7b7ee2612456cad4cb83f5b: blobmsg_parse: ... (0) + crash-5e9937b197c88bf4e7b7ee2612456cad4cb83f5b: blobmsg_parse_array: ... (-1) + crash-75b146c4e6fac64d3e62236b27c64b50657bab2a: blobmsg_parse: ... (0) + crash-75b146c4e6fac64d3e62236b27c64b50657bab2a: blobmsg_parse_array: ... (-1) + crash-75b146c4e6fac64d3e62236b27c64b50657bab2a: blobmsg_parse: ... (0) + crash-75b146c4e6fac64d3e62236b27c64b50657bab2a: blobmsg_parse_array: ... (-1) + crash-813f3e68661da09c26d4a87dbb9d5099e92be50f: blobmsg_parse: ... (0) + crash-813f3e68661da09c26d4a87dbb9d5099e92be50f: blobmsg_parse_array: ... (-1) + crash-813f3e68661da09c26d4a87dbb9d5099e92be50f: blobmsg_parse: ... (0) + crash-813f3e68661da09c26d4a87dbb9d5099e92be50f: blobmsg_parse_array: ... (-1) + crash-98595faa58ba01d85ba4fd0b109cd3d490b45795: blobmsg_parse: ... (0) + crash-98595faa58ba01d85ba4fd0b109cd3d490b45795: blobmsg_parse_array: ... (0) + crash-98595faa58ba01d85ba4fd0b109cd3d490b45795: blobmsg_parse: ... (0) + crash-98595faa58ba01d85ba4fd0b109cd3d490b45795: blobmsg_parse_array: ... (0) + crash-d0f3aa7d60a094b021f635d4edb7807c055a4ea1: blobmsg_parse: ... (0) + crash-d0f3aa7d60a094b021f635d4edb7807c055a4ea1: blobmsg_parse_array: ... (0) + crash-d0f3aa7d60a094b021f635d4edb7807c055a4ea1: blobmsg_parse: ... (0) + crash-d0f3aa7d60a094b021f635d4edb7807c055a4ea1: blobmsg_parse_array: ... (0) + crash-df9d1243057b27bbad6211e5a23d1cb699028aa2: blobmsg_parse: ... (0) + crash-df9d1243057b27bbad6211e5a23d1cb699028aa2: blobmsg_parse_array: ... (0) + crash-df9d1243057b27bbad6211e5a23d1cb699028aa2: blobmsg_parse: ... (0) + crash-df9d1243057b27bbad6211e5a23d1cb699028aa2: blobmsg_parse_array: ... (0) + crash-e2fd5ecb3b37926743256f1083f47a07c39e10c2: blobmsg_parse: ... (0) + crash-e2fd5ecb3b37926743256f1083f47a07c39e10c2: blobmsg_parse_array: ... (-1) + crash-e2fd5ecb3b37926743256f1083f47a07c39e10c2: blobmsg_parse: ... (0) + crash-e2fd5ecb3b37926743256f1083f47a07c39e10c2: blobmsg_parse_array: ... (-1) + valid-blobmsg.bin: blobmsg_parse: MLT (0) + valid-blobmsg.bin: blobmsg_parse_array: MLT (0) + valid-blobmsg.bin: blobmsg_parse: MLT (0) + valid-blobmsg.bin: blobmsg_parse_array: MLT (0) diff --git a/tests/test-blobmsg-parse.c b/tests/test-blobmsg-parse.c new file mode 100644 index 0000000..ca710fd --- /dev/null +++ b/tests/test-blobmsg-parse.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include + +#include "blobmsg.h" + +enum { + FOO_MESSAGE, + FOO_LIST, + FOO_TESTDATA, + __FOO_MAX +}; + +static const struct blobmsg_policy foo_policy[] = { + [FOO_MESSAGE] = { + .name = "message", + .type = BLOBMSG_TYPE_STRING, + }, + [FOO_LIST] = { + .name = "list", + .type = BLOBMSG_TYPE_ARRAY, + }, + [FOO_TESTDATA] = { + .name = "testdata", + .type = BLOBMSG_TYPE_TABLE, + }, +}; + +static void dump_result(const char *fn, int r, const char *filename, struct blob_attr **tb) +{ + fprintf(stdout, "%s: %s: %c%c%c (%d)\n", basename((char *) filename), fn, + tb[FOO_MESSAGE] ? 'M' : '.', + tb[FOO_LIST] ? 'L' : '.', + tb[FOO_TESTDATA] ? 'T' : '.', + r); +} + +static void test_blobmsg(const char *filename) +{ +#define BUF_LEN 256 + int r = 0; + FILE *fd = NULL; + size_t len = 0; + char buf[BUF_LEN+1] = { 0 }; + struct blob_attr *tb[__FOO_MAX]; + + fd = fopen(filename, "r"); + if (!fd) { + fprintf(stderr, "unable to open %s", filename); + return; + } + + len = fread(&buf, 1, BUF_LEN, fd); + fclose(fd); + + r = blobmsg_parse(foo_policy, ARRAY_SIZE(foo_policy), tb, buf, len); + dump_result("blobmsg_parse", r, filename, tb); + + r = blobmsg_parse_array(foo_policy, ARRAY_SIZE(foo_policy), tb, buf, len); + dump_result("blobmsg_parse_array", r, filename, tb); +} + +int main(int argc, char *argv[]) +{ + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 3; + } + + test_blobmsg(argv[1]); + + return 0; +} -- 2.25.1