Debian Codegraph @

debian/tests/test-helper

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_helper_runner.c
17 #include <fcntl.h>
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <errno.h>
22
23 #define _XOPEN_SOURCE 600
24 #define __USE_XOPEN2KXSI
25 #define __USE_XOPEN_EXTENDED
26 #include <stdlib.h>
27
28 #define CHECK(x) do { \
29 int _ret = (x); \
30 if (_ret != 0) { \
31 printf(#x " returned %d: %s\n", _ret, strerror(errno)); \
32 exit (1); \
33 } \
34 } while(0)
35
36 int main()
37 {
38 setbuf(stdout, NULL);
39
40 const int i = posix_openpt(O_RDWR | O_NOCTTY);
41 printf("## open ptmx returned %d\n", i);
42
43 CHECK(grantpt(i));
44 CHECK(unlockpt(i));
45
46 printf("## ptsname: %s\n", ptsname(i));
47
48 dup2(i, 0);
49
50 printf("## doing utempter add\n");
51 CHECK(system("/usr/lib/$(dpkg-architecture --query DEB_HOST_MULTIARCH)/utempter/utempter add hostname_test_314159265359"));
52
53 printf("## checking who\n");
54 CHECK(system("who -a /run/utmp"));
55
56 printf("## doing utempter del\n");
57 CHECK(system("/usr/lib/$(dpkg-architecture --query DEB_HOST_MULTIARCH)/utempter/utempter del"));
58
59 printf("## checking who\n");
60 CHECK(system("who -a /run/utmp"));
61
62 printf("## DONE\n");
63
64 return 0;
65 }
66 EOF
67
68 ${CROSS_COMPILE} -Wall -Wextra -Werror -O2 test_helper_runner.c -o test_helper_runner
69 ./test_helper_runner
70 if [ $(./test_helper_runner | grep -c hostname_test_314159265359) -ne 1 ]; then
71 echo "inserted hostname not found"
72 exit 1
73 else
74 echo "inserted hostname found"
75 fi