]> git.saurik.com Git - apple/copyfile.git/blame - copyfile_test/main.c
copyfile-173.40.2.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
85b8a2cb
A
14#include "identical_test.h"
15#include "readonly_fd_test.h"
937356ff 16#include "sparse_test.h"
23896e53 17#include "stat_test.h"
85b8a2cb 18#include "xattr_test.h"
937356ff
A
19#include "test_utils.h"
20
21#define DISK_IMAGE_SIZE_MB 512
22
23#if TARGET_OS_OSX
24#define TEST_DIR MOUNT_PATH
25#define USING_DISK_IMAGE 1
26#else
27#define TEST_DIR "/tmp/copyfile_test"
28#define USING_DISK_IMAGE 0
29#endif // TARGET_OS_OSX
30
31#define MIN_BLOCKSIZE_B 512
32#define DEFAULT_BLOCKSIZE_B 4096
33#define MAX_BLOCKSIZE_B 16384
34
35int main(__unused int argc, __unused const char * argv[]) {
36 bool failed = false;
37 struct statfs stb;
38
39 // Create a disk image to run our tests in.
40 if (USING_DISK_IMAGE) {
41 disk_image_create(APFS_FSTYPE, DISK_IMAGE_SIZE_MB);
42 } else {
43 (void)removefile(TEST_DIR, NULL, REMOVEFILE_RECURSIVE);
44 assert_no_err(mkdir(TEST_DIR, 0777));
45 }
46
47 // Make sure the test directory exists, is apfs formatted,
48 // and that we have a sane block size.
49 assert_no_err(statfs(TEST_DIR, &stb));
50 assert_no_err(memcmp(stb.f_fstypename, APFS_FSTYPE, sizeof(APFS_FSTYPE)));
51 if (stb.f_bsize < MIN_BLOCKSIZE_B || stb.f_bsize > MAX_BLOCKSIZE_B) {
52 stb.f_bsize = DEFAULT_BLOCKSIZE_B;
53 }
54
55 // Run our tests.
56 sranddev();
85b8a2cb 57 failed |= do_readonly_fd_test(TEST_DIR, stb.f_bsize);
937356ff
A
58 failed |= do_sparse_test(TEST_DIR, stb.f_bsize);
59 failed |= do_sparse_recursive_test(TEST_DIR, stb.f_bsize);
60 failed |= do_fcopyfile_offset_test(TEST_DIR, stb.f_bsize);
23896e53 61 failed |= do_preserve_dst_flags_test(TEST_DIR, stb.f_bsize);
62b275d9 62 failed |= do_preserve_dst_tracked_test(TEST_DIR, stb.f_bsize);
85b8a2cb
A
63 failed |= do_src_dst_identical_test(TEST_DIR, stb.f_bsize);
64 failed |= do_xattr_test(TEST_DIR, stb.f_bsize);
937356ff
A
65
66 // Cleanup the disk image we ran our tests on.
67 if (USING_DISK_IMAGE) {
68 disk_image_destroy(false);
69 } else {
70 (void)removefile(TEST_DIR, NULL, REMOVEFILE_RECURSIVE);
71 }
72
73 return failed ? EXIT_FAILURE : EXIT_SUCCESS;
74}