xref: /xnu-8796.121.2/tools/tests/perf_index/perfindex-compile.c (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1*c54f35caSApple OSS Distributions #include "perf_index.h"
2*c54f35caSApple OSS Distributions #include "fail.h"
3*c54f35caSApple OSS Distributions #include <stdio.h>
4*c54f35caSApple OSS Distributions #include <stdlib.h>
5*c54f35caSApple OSS Distributions 
6*c54f35caSApple OSS Distributions static const char *src_dst = "/tmp/perf_index_compile_code";
7*c54f35caSApple OSS Distributions static const char *src_root = "/Network/Servers/xs1/release/Software/Zin/Projects/xnu/xnu-2050.7.9";
8*c54f35caSApple OSS Distributions 
9*c54f35caSApple OSS Distributions DECL_SETUP {
10*c54f35caSApple OSS Distributions 	char* cmd;
11*c54f35caSApple OSS Distributions 	int retval;
12*c54f35caSApple OSS Distributions 	const char *src = src_root;
13*c54f35caSApple OSS Distributions 	if (test_argc >= 1) {
14*c54f35caSApple OSS Distributions 		src = (char*)test_argv[0];
15*c54f35caSApple OSS Distributions 	}
16*c54f35caSApple OSS Distributions 
17*c54f35caSApple OSS Distributions 	retval = asprintf(&cmd, "ditto \"%s\" \"%s\"", src, src_dst);
18*c54f35caSApple OSS Distributions 	VERIFY(retval > 0, "asprintf failed");
19*c54f35caSApple OSS Distributions 
20*c54f35caSApple OSS Distributions 	retval = system(cmd);
21*c54f35caSApple OSS Distributions 	VERIFY(retval == 0, "ditto command failed");
22*c54f35caSApple OSS Distributions 
23*c54f35caSApple OSS Distributions 	free(cmd);
24*c54f35caSApple OSS Distributions 
25*c54f35caSApple OSS Distributions 	return PERFINDEX_SUCCESS;
26*c54f35caSApple OSS Distributions }
27*c54f35caSApple OSS Distributions 
28*c54f35caSApple OSS Distributions DECL_TEST {
29*c54f35caSApple OSS Distributions 	char* cmd;
30*c54f35caSApple OSS Distributions 	int retval;
31*c54f35caSApple OSS Distributions 
32*c54f35caSApple OSS Distributions 	if (thread_id != 0) {
33*c54f35caSApple OSS Distributions 		return 0;
34*c54f35caSApple OSS Distributions 	}
35*c54f35caSApple OSS Distributions 
36*c54f35caSApple OSS Distributions 	retval = asprintf(&cmd, "make -C \"%s\" MAKEJOBS=-j%d", src_dst, num_threads);
37*c54f35caSApple OSS Distributions 	VERIFY(retval > 0, "asprintf failed");
38*c54f35caSApple OSS Distributions 
39*c54f35caSApple OSS Distributions 	retval = system(cmd);
40*c54f35caSApple OSS Distributions 	VERIFY(retval == 0, "make command failed");
41*c54f35caSApple OSS Distributions 
42*c54f35caSApple OSS Distributions 	return PERFINDEX_SUCCESS;
43*c54f35caSApple OSS Distributions }
44*c54f35caSApple OSS Distributions 
45*c54f35caSApple OSS Distributions DECL_CLEANUP {
46*c54f35caSApple OSS Distributions 	char* cmd;
47*c54f35caSApple OSS Distributions 	int retval;
48*c54f35caSApple OSS Distributions 
49*c54f35caSApple OSS Distributions 	retval = asprintf(&cmd, "rm -rf \"%s\"", src_dst);
50*c54f35caSApple OSS Distributions 	VERIFY(retval > 0, "asprintf failed");
51*c54f35caSApple OSS Distributions 
52*c54f35caSApple OSS Distributions 	retval = system(cmd);
53*c54f35caSApple OSS Distributions 	VERIFY(retval == 0, "rm command failed");
54*c54f35caSApple OSS Distributions 
55*c54f35caSApple OSS Distributions 	return PERFINDEX_SUCCESS;
56*c54f35caSApple OSS Distributions }
57