1 /* Test sysconf with an empty chroot.
2 Copyright (C) 2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
21 #include <support/check.h>
22 #include <support/namespace.h>
23 #include <support/support.h>
24 #include <support/temp_file.h>
25 #include <support/test-driver.h>
26 #include <support/xunistd.h>
29 /* Check for an SMP system in a forked process, so that the parent
30 process does not cache the value. */
32 is_smp_callback (void *closure
)
34 bool *result
= closure
;
36 long cpus
= sysconf (_SC_NPROCESSORS_ONLN
);
37 TEST_VERIFY_EXIT (cpus
> 0);
44 bool *result
= support_shared_allocate (sizeof (*result
));
45 support_isolate_in_subprocess (is_smp_callback
, result
);
46 bool result_copy
= *result
;
47 support_shared_free (result
);
51 static char *path_chroot
;
53 /* Prepare an empty directory, to be used as a chroot. */
55 prepare (int argc
, char **argv
)
57 path_chroot
= xasprintf ("%s/tst-resolv-res_init-XXXXXX", test_dir
);
58 if (mkdtemp (path_chroot
) == NULL
)
59 FAIL_EXIT1 ("mkdtemp (\"%s\"): %m", path_chroot
);
60 add_temp_file (path_chroot
);
63 /* The actual test. Run it in a subprocess, so that the test harness
64 can remove the temporary directory in --direct mode. */
66 chroot_callback (void *closure
)
68 xchroot (path_chroot
);
69 long cpus
= sysconf (_SC_NPROCESSORS_ONLN
);
70 printf ("info: sysconf (_SC_NPROCESSORS_ONLN) in chroot: %ld\n", cpus
);
71 TEST_VERIFY (cpus
> 0);
72 TEST_VERIFY (cpus
!= 1);
81 printf ("warning: test not supported on uniprocessor system\n");
82 return EXIT_UNSUPPORTED
;
85 support_become_root ();
86 if (!support_can_chroot ())
87 return EXIT_UNSUPPORTED
;
89 support_isolate_in_subprocess (chroot_callback
, NULL
);
94 #define PREPARE prepare
95 #include <support/test-driver.c>