]> git.saurik.com Git - apple/xnu.git/blob - tools/tests/perf_index/stress_file_ram.c
xnu-2422.1.72.tar.gz
[apple/xnu.git] / tools / tests / perf_index / stress_file_ram.c
1 #include <fcntl.h>
2 #include "perf_index.h"
3 #include <errno.h>
4
5 #define MAX_FILE_SIZE 536870912L
6
7 const stress_test_t file_ram_create_test = {"ram_file_create", &stress_file_ram_create_init, &stress_file_ram_create, &stress_file_ram_create_cleanup, &no_validate};
8 const stress_test_t file_ram_write_test = {"ram_file_write", &stress_file_ram_write_init, &stress_file_ram_write, &stress_file_ram_write_cleanup, &no_validate};
9 const stress_test_t file_ram_read_test = {"ram_file_read", &stress_file_ram_read_init, &stress_file_ram_read, &stress_file_ram_read_cleanup, &no_validate};
10
11 static const char ramdiskname[] = "StressRamDisk";
12
13 static const char fs_path[MAXPATHLEN] = "/Volumes/StressRamDisk";
14
15 static void setup_ram_volume(void) {
16 char *cmd;
17 assert(asprintf(&cmd, "diskutil erasevolume HFS+ \"%s\" `hdiutil attach -nomount ram://1500000` >/dev/null", ramdiskname) >= 0);
18 assert(system(cmd) == 0);
19 free(cmd);
20 }
21
22 static void cleanup_ram_volume(void) {
23 char *cmd;
24 assert(asprintf(&cmd, "umount -f %s >/dev/null", fs_path) >= 0);
25 assert(system(cmd) == 0);
26 free(cmd);
27 }
28
29 DECL_INIT(stress_file_ram_read_init) {
30 setup_ram_volume();
31 stress_file_read_init(fs_path, num_threads, length, MAX_FILE_SIZE);
32 }
33
34 DECL_TEST(stress_file_ram_read) {
35 stress_file_read(fs_path, thread_id, num_threads, length, MAX_FILE_SIZE);
36 }
37
38 DECL_CLEANUP(stress_file_ram_read_cleanup) {
39 cleanup_ram_volume();
40 }
41
42 DECL_INIT(stress_file_ram_write_init) {
43 setup_ram_volume();
44 stress_file_write_init(fs_path, num_threads, length);
45 }
46
47 DECL_TEST(stress_file_ram_write) {
48 stress_file_write(fs_path, thread_id, num_threads, length, MAX_FILE_SIZE);
49 }
50
51 DECL_CLEANUP(stress_file_ram_write_cleanup) {
52 cleanup_ram_volume();
53 }
54
55 DECL_INIT(stress_file_ram_create_init) {
56 setup_ram_volume();
57 }
58
59 DECL_TEST(stress_file_ram_create) {
60 stress_file_create(fs_path, thread_id, num_threads, length);
61 }
62
63 DECL_CLEANUP(stress_file_ram_create_cleanup) {
64 cleanup_ram_volume();
65 }