Debian Codegraph @

debian/tests/test-library2

raw
1 #!/bin/sh
2
3 set -eu
4
5 if [ ! -e /var/run/utmp ]; then
6 echo "/var/run/utmp does not exist; skipping test"
7 exit 77
8 fi
9
10 if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then
11 CROSS_COMPILE="$DEB_HOST_GNU_TYPE-gcc"
12 else
13 CROSS_COMPILE="cc"
14 fi
15
16 cat <<EOF > test_library2_runner.c
17 #include <fcntl.h>
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <errno.h>
22
23 #include <utempter.h>
24
25 #define _XOPEN_SOURCE 600
26 #define __USE_XOPEN2KXSI
27 #define __USE_XOPEN_EXTENDED
28 #include <stdlib.h>
29
30 #define CHECK(x) do { \
31 int _ret = (x); \
32 if (_ret != 0) { \
33 printf(#x " returned %d: %s\n", _ret, strerror(errno)); \
34 exit (1); \
35 } \
36 } while(0)
37
38 int main()
39 {
40 setbuf(stdout, NULL);
41
42 const int i = posix_openpt(O_RDWR | O_NOCTTY);
43 printf("## open ptmx returned %d\n", i);
44
45 CHECK(grantpt(i));
46 CHECK(unlockpt(i));
47
48 printf("## ptsname: %s\n", ptsname(i));
49
50 printf("## doing libutempter add\n");
51 CHECK(!utempter_add_record(i, "hostname_test_161803398875"));
52
53 printf("## checking who\n");
54 CHECK(system("who -a /run/utmp"));
55
56 printf("## doing libutempter del\n");
57 CHECK(!utempter_remove_added_record());
58
59 printf("## checking who\n");
60 CHECK(system("who -a /run/utmp"));
61
62 printf("## DONE\n");
63 }
64 EOF
65
66 ${CROSS_COMPILE} -Wall -Wextra -Werror -O2 test_library2_runner.c -lutempter -o test_library2_runner
67 ./test_library2_runner
68 if [ $(./test_library2_runner | grep -c hostname_test_161803398875) -ne 1 ]; then
69 echo "inserted hostname not found"
70 exit 1
71 else
72 echo "inserted hostname found"
73 fi