• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of sysinfo strace test.
3  *
4  * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
5  * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
6  * Copyright (c) 2015-2017 The strace developers.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "tests.h"
33 #include <stdio.h>
34 #include <sys/sysinfo.h>
35 
36 int
main(void)37 main(void)
38 {
39 	sysinfo(NULL);
40 	printf("sysinfo(NULL) = -1 EFAULT (%m)\n");
41 
42 	TAIL_ALLOC_OBJECT_CONST_PTR(struct sysinfo, si);
43 
44 	if (sysinfo(si))
45 		perror_msg_and_skip("sysinfo");
46 	printf("sysinfo({uptime=%llu"
47 		", loads=[%llu, %llu, %llu]"
48 		", totalram=%llu"
49 		", freeram=%llu"
50 		", sharedram=%llu"
51 		", bufferram=%llu"
52 		", totalswap=%llu"
53 		", freeswap=%llu"
54 		", procs=%u"
55 		", totalhigh=%llu"
56 		", freehigh=%llu"
57 		", mem_unit=%u"
58 		"}) = 0\n"
59 		, (unsigned long long) si->uptime
60 		, (unsigned long long) si->loads[0]
61 		, (unsigned long long) si->loads[1]
62 		, (unsigned long long) si->loads[2]
63 		, (unsigned long long) si->totalram
64 		, (unsigned long long) si->freeram
65 		, (unsigned long long) si->sharedram
66 		, (unsigned long long) si->bufferram
67 		, (unsigned long long) si->totalswap
68 		, (unsigned long long) si->freeswap
69 		, (unsigned) si->procs
70 		, (unsigned long long) si->totalhigh
71 		, (unsigned long long) si->freehigh
72 		, si->mem_unit
73 		);
74 
75 	puts("+++ exited with 0 +++");
76 	return 0;
77 }
78