Debian Codegraph @

debian/tests/build

raw
1 #!/bin/sh
2 # autopkgtest check: Build and run a program against liblognorm, to verify that
3 # the headers are correctly installed
4
5 set -e
6
7 if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then
8 CROSS_COMPILE=${DEB_HOST_GNU_TYPE}-
9 else
10 CROSS_COMPILE=
11 fi
12
13 WORKDIR="$(mktemp -d)"
14 trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
15 cd "$WORKDIR"
16 cat <<.EOF > lognorm_test.c
17 #include <liblognorm.h>
18 #include <string.h>
19
20 int main(void)
21 {
22 printf("liblognorm version: %s\n", ln_version());
23
24 ln_ctx ctx = ln_initCtx();
25 if (ctx == NULL) {
26 printf("ln_initCtx failed\n");
27 return 1;
28 }
29
30 const char rule[] = "rule=syslog:%date1:date-rfc3164% %host:word% %tag:char-to:\x3a%: %text:rest%"; // from sample.rulebase
31 int load = ln_loadSamplesFromString(ctx, rule);
32 if (load != 0) {
33 printf("ln_loadSamplesFromString failed\n");
34 return 1;
35 }
36
37 const char message[] = "Oct 29 09:47:08 server rsyslogd: rsyslogd's groupid changed to 103"; // from sample.rulebase
38 struct json_object *json = NULL;
39 int norm = ln_normalize(ctx, message, strlen(message), &json);
40 if (norm != 0 || json == NULL) {
41 printf("ln_normalize failed\n");
42 return 1;
43 }
44
45 return 0;
46 }
47 .EOF
48
49 ${CROSS_COMPILE}gcc -pedantic -Wall -Werror -o lognorm_test lognorm_test.c $(pkgconf --cflags --libs lognorm)
50 echo "build: OK"
51 [ -x lognorm_test ]
52 ./lognorm_test
53 echo "run: OK"