File: test_qemuarch.c

package info (click to toggle)
cowdancer 0.90
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 648 kB
  • sloc: ansic: 4,593; sh: 407; makefile: 142; cpp: 5
file content (61 lines) | stat: -rw-r--r-- 1,447 bytes parent folder | download | duplicates (5)
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
/*
 * test qemubuilder code
 */

#define _GNU_SOURCE
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "qemuarch.h"

int test_get_host_dpkg_arch() {
/* just try to test x86_64 case */
#if defined(__x86_64__)
#if defined(__ILP32__)
	assert(!strcmp(get_host_dpkg_arch(), "x32"));
#else
	assert(!strcmp(get_host_dpkg_arch(), "amd64"));
#endif
#elif defined(__i386__)
	assert((!strcmp(get_host_dpkg_arch(), "i386")) ||
		   (!strcmp(get_host_dpkg_arch(), "lpia")));
#else
	printf("W: no check for this architecture\n");
#endif
	return 0;
}

int test_qemu_create_arch_devices() {
	char *temp = strdupa("/tmp/dancerXXXXXX");
	temp = mkdtemp(temp);
	printf("%s\n", temp);

	/* if you are running this in normal user, or running through
	 * fakeroot, you would (probably) get this */
	if (getuid() != 0 ||
		(getenv("FAKEROOTKEY") && strcmp(getenv("FAKEROOTKEY"), ""))) {
		assert(qemu_create_arch_devices(temp, "x86_64") < 0);
	} else {
		/* if you are running this as root,
		 * this would be the tested codepath. */
		struct stat s;
		umask(S_IWOTH);
		assert(qemu_create_arch_devices(temp, "x86_64") == 0);
		chdir(temp);
		assert(stat("./dev/ttyAMA0", &s) == 0);
		assert(S_ISCHR(s.st_mode));
	}
	return 0;
}

int main() {
	int val = 0;
	val += test_get_host_dpkg_arch();
	val += test_qemu_create_arch_devices();
	return val;
}