]> git.saurik.com Git - apple/copyfile.git/blame - copyfile_test/main.c
copyfile-146.50.5.tar.gz
[apple/copyfile.git] / copyfile_test / main.c
CommitLineData
937356ff
A
1//
2// main.c
3// copyfile_test
4//
5
6#include <stdbool.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <sys/mount.h>
11#include <sys/stat.h>
12#include <removefile.h>
13
14#include "sparse_test.h"
15#include "test_utils.h"
16
17#define DISK_IMAGE_SIZE_MB 512
18
19#if TARGET_OS_OSX
20#define TEST_DIR MOUNT_PATH
21#define USING_DISK_IMAGE 1
22#else
23#define TEST_DIR "/tmp/copyfile_test"
24#define USING_DISK_IMAGE 0
25#endif // TARGET_OS_OSX
26
27#define MIN_BLOCKSIZE_B 512
28#define DEFAULT_BLOCKSIZE_B 4096
29#define MAX_BLOCKSIZE_B 16384
30
31int main(__unused int argc, __unused const char * argv[]) {
32 bool failed = false;
33 struct statfs stb;
34
35 // Create a disk image to run our tests in.
36 if (USING_DISK_IMAGE) {
37 disk_image_create(APFS_FSTYPE, DISK_IMAGE_SIZE_MB);
38 } else {
39 (void)removefile(TEST_DIR, NULL, REMOVEFILE_RECURSIVE);
40 assert_no_err(mkdir(TEST_DIR, 0777));
41 }
42
43 // Make sure the test directory exists, is apfs formatted,
44 // and that we have a sane block size.
45 assert_no_err(statfs(TEST_DIR, &stb));
46 assert_no_err(memcmp(stb.f_fstypename, APFS_FSTYPE, sizeof(APFS_FSTYPE)));
47 if (stb.f_bsize < MIN_BLOCKSIZE_B || stb.f_bsize > MAX_BLOCKSIZE_B) {
48 stb.f_bsize = DEFAULT_BLOCKSIZE_B;
49 }
50
51 // Run our tests.
52 sranddev();
53 failed |= do_sparse_test(TEST_DIR, stb.f_bsize);
54 failed |= do_sparse_recursive_test(TEST_DIR, stb.f_bsize);
55 failed |= do_fcopyfile_offset_test(TEST_DIR, stb.f_bsize);
56
57 // Cleanup the disk image we ran our tests on.
58 if (USING_DISK_IMAGE) {
59 disk_image_destroy(false);
60 } else {
61 (void)removefile(TEST_DIR, NULL, REMOVEFILE_RECURSIVE);
62 }
63
64 return failed ? EXIT_FAILURE : EXIT_SUCCESS;
65}