File: log-test.c

package info (click to toggle)
slurm-wlm-contrib 24.11.5-2
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 50,596 kB
  • sloc: ansic: 529,598; exp: 64,795; python: 17,051; sh: 9,411; javascript: 6,528; makefile: 4,030; perl: 3,762; pascal: 131
file content (67 lines) | stat: -rw-r--r-- 1,461 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

#include <slurm/slurm_errno.h>
#include "src/common/log.h"

int bad_func()
{
	slurm_seterrno_ret(EINVAL);
}
int main(int ac, char **av)
{
	/* test elements */
	char string[]  = "test string";
	double f       = 9876543210.0123456;
	int   i        = 67890;
	int   negi     = -i;
	unsigned int u = 1234;
	char *p        = NULL;

	log_options_t log_opts = LOG_OPTS_INITIALIZER;

	log_opts.stderr_level = LOG_LEVEL_DEBUG2;

	/* test log to stderr when log not initialized */
	error("testing with unitialized log.");

	/* now initialize log: */
	log_init("log-test", log_opts, 0, NULL);

	error  ("testing error");
	info   ("testing info ");
	verbose("testing verbose");
	debug  ("testing debug level 1");
	debug2 ("testing debug level 2");
	debug3 ("ERROR: Should not see this.");

	info   ("testing print of null pointer: %p = %s",  p, p);

	info   ("testing double: %18.7f int: %05i string `%s'", f, i, string);

	info   ("testing unsigned: %u   int: % 08d", u, negi);

	switch (fork()) {
          case 0:
		  info("in child %ld", (long int) getpid());
		  log_reinit();
		  info("in child after log reinit");
		  exit(0);
		  break;
	  case -1:
		  error("fork: %m");
		  break;
	  default:
		  info("in parent %ld", (long int) getpid());
		  break;
	}
	/* for now, this test passes if we make it through without 
	 * dumping core
	 */

	if (bad_func() < 0)
		error("bad_func: %m");
	return 0;
}