ANDROID: Incremental fs: Clean up incfs_test build process
Bug: 153557975 Test: incfs_test passes Signed-off-by: Paul Lawrence <paullawrence@google.com> Change-Id: I57eef43a5d003e3d89a4c872d21e36376bc580a1
This commit is contained in:
@@ -1,18 +1,11 @@
|
|||||||
# SPDX-License-Identifier: GPL-2.0
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
CFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -lssl -lcrypto -llz4
|
CFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall
|
||||||
CFLAGS += -I../../../../../usr/include/
|
CFLAGS += -I../.. -I../../../../..
|
||||||
CFLAGS += -I../../../../include/uapi/
|
|
||||||
CFLAGS += -I../../../../lib
|
|
||||||
|
|
||||||
|
LDLIBS := -llz4 -lcrypto
|
||||||
EXTRA_SOURCES := utils.c
|
EXTRA_SOURCES := utils.c
|
||||||
CFLAGS += $(EXTRA_SOURCES)
|
|
||||||
|
|
||||||
TEST_GEN_PROGS := incfs_test
|
TEST_GEN_PROGS := incfs_test
|
||||||
|
|
||||||
|
$(TEST_GEN_PROGS): $(EXTRA_SOURCES)
|
||||||
|
|
||||||
include ../../lib.mk
|
include ../../lib.mk
|
||||||
|
|
||||||
$(OUTPUT)incfs_test: incfs_test.c $(EXTRA_SOURCES)
|
|
||||||
all: $(OUTPUT)incfs_test
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf $(OUTPUT)incfs_test *.o
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
CONFIG_INCREMENTAL_FS=y
|
|
||||||
@@ -2,27 +2,29 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 Google LLC
|
* Copyright 2018 Google LLC
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/mount.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <sys/xattr.h>
|
|
||||||
#include <alloca.h>
|
#include <alloca.h>
|
||||||
#include <string.h>
|
#include <dirent.h>
|
||||||
#include <stdio.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <lz4.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <sys/mount.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <sys/xattr.h>
|
||||||
|
|
||||||
#include <linux/random.h>
|
#include <linux/random.h>
|
||||||
#include <linux/unistd.h>
|
#include <linux/unistd.h>
|
||||||
|
|
||||||
#include "../../kselftest.h"
|
#include <kselftest.h>
|
||||||
|
|
||||||
#include "lz4.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#define TEST_FAILURE 1
|
#define TEST_FAILURE 1
|
||||||
@@ -208,7 +210,7 @@ int open_file_by_id(const char *mnt_dir, incfs_uuid_t id, bool use_ioctl)
|
|||||||
{
|
{
|
||||||
char *path = get_index_filename(mnt_dir, id);
|
char *path = get_index_filename(mnt_dir, id);
|
||||||
int cmd_fd = open_commands_file(mnt_dir);
|
int cmd_fd = open_commands_file(mnt_dir);
|
||||||
int fd = open(path, O_RDWR);
|
int fd = open(path, O_RDWR | O_CLOEXEC);
|
||||||
struct incfs_permit_fill permit_fill = {
|
struct incfs_permit_fill permit_fill = {
|
||||||
.file_descriptor = fd,
|
.file_descriptor = fd,
|
||||||
};
|
};
|
||||||
@@ -281,7 +283,7 @@ static int emit_test_blocks(char *mnt_dir, struct test_file *file,
|
|||||||
.fill_blocks = ptr_to_u64(block_buf),
|
.fill_blocks = ptr_to_u64(block_buf),
|
||||||
};
|
};
|
||||||
ssize_t write_res = 0;
|
ssize_t write_res = 0;
|
||||||
int fd;
|
int fd = -1;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int blocks_written = 0;
|
int blocks_written = 0;
|
||||||
@@ -444,7 +446,7 @@ static loff_t read_whole_file(char *filename)
|
|||||||
loff_t bytes_read = 0;
|
loff_t bytes_read = 0;
|
||||||
uint8_t buff[16 * 1024];
|
uint8_t buff[16 * 1024];
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY | O_CLOEXEC);
|
||||||
if (fd <= 0)
|
if (fd <= 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
@@ -476,7 +478,7 @@ static int read_test_file(uint8_t *buf, size_t len, char *filename,
|
|||||||
size_t bytes_to_read = len;
|
size_t bytes_to_read = len;
|
||||||
off_t offset = ((off_t)block_idx) * INCFS_DATA_FILE_BLOCK_SIZE;
|
off_t offset = ((off_t)block_idx) * INCFS_DATA_FILE_BLOCK_SIZE;
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY | O_CLOEXEC);
|
||||||
if (fd <= 0)
|
if (fd <= 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
@@ -909,7 +911,7 @@ static bool iterate_directory(char *dir_to_iterate, bool root, int file_count)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Test directory iteration */
|
/* Test directory iteration */
|
||||||
int fd = open(dir_to_iterate, O_RDONLY | O_DIRECTORY);
|
int fd = open(dir_to_iterate, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
print_error("Can't open directory\n");
|
print_error("Can't open directory\n");
|
||||||
@@ -1110,7 +1112,7 @@ static int basic_file_ops_test(char *mount_dir)
|
|||||||
char *path = concat_file_name(mount_dir, file->name);
|
char *path = concat_file_name(mount_dir, file->name);
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(path, O_RDWR);
|
fd = open(path, O_RDWR | O_CLOEXEC);
|
||||||
free(path);
|
free(path);
|
||||||
if (fd <= 0) {
|
if (fd <= 0) {
|
||||||
print_error("Can't open file");
|
print_error("Can't open file");
|
||||||
@@ -1943,7 +1945,7 @@ static int validate_logs(char *mount_dir, int log_fd, struct test_file *file,
|
|||||||
char *filename = concat_file_name(mount_dir, file->name);
|
char *filename = concat_file_name(mount_dir, file->name);
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY | O_CLOEXEC);
|
||||||
free(filename);
|
free(filename);
|
||||||
if (fd <= 0)
|
if (fd <= 0)
|
||||||
return TEST_FAILURE;
|
return TEST_FAILURE;
|
||||||
@@ -2125,7 +2127,7 @@ static int read_log_test(char *mount_dir)
|
|||||||
/*
|
/*
|
||||||
* Remount and check that logs start working again
|
* Remount and check that logs start working again
|
||||||
*/
|
*/
|
||||||
drop_caches = open("/proc/sys/vm/drop_caches", O_WRONLY);
|
drop_caches = open("/proc/sys/vm/drop_caches", O_WRONLY | O_CLOEXEC);
|
||||||
if (drop_caches == -1)
|
if (drop_caches == -1)
|
||||||
goto failure;
|
goto failure;
|
||||||
i = write(drop_caches, "3", 1);
|
i = write(drop_caches, "3", 1);
|
||||||
@@ -2215,7 +2217,7 @@ static int validate_ranges(const char *mount_dir, struct test_file *file)
|
|||||||
int cmd_fd = -1;
|
int cmd_fd = -1;
|
||||||
struct incfs_permit_fill permit_fill;
|
struct incfs_permit_fill permit_fill;
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY | O_CLOEXEC);
|
||||||
free(filename);
|
free(filename);
|
||||||
if (fd <= 0)
|
if (fd <= 0)
|
||||||
return TEST_FAILURE;
|
return TEST_FAILURE;
|
||||||
@@ -2455,7 +2457,7 @@ static int validate_hash_ranges(const char *mount_dir, struct test_file *file)
|
|||||||
if (file->size <= 4096 / 32 * 4096)
|
if (file->size <= 4096 / 32 * 4096)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY | O_CLOEXEC);
|
||||||
free(filename);
|
free(filename);
|
||||||
if (fd <= 0)
|
if (fd <= 0)
|
||||||
return TEST_FAILURE;
|
return TEST_FAILURE;
|
||||||
@@ -2590,7 +2592,7 @@ int main(int argc, char *argv[])
|
|||||||
// NOTE - this abuses the concept of randomness - do *not* ever do this
|
// NOTE - this abuses the concept of randomness - do *not* ever do this
|
||||||
// on a machine for production use - the device will think it has good
|
// on a machine for production use - the device will think it has good
|
||||||
// randomness when it does not.
|
// randomness when it does not.
|
||||||
fd = open("/dev/urandom", O_WRONLY);
|
fd = open("/dev/urandom", O_WRONLY | O_CLOEXEC);
|
||||||
count = 4096;
|
count = 4096;
|
||||||
for (int i = 0; i < 128; ++i)
|
for (int i = 0; i < 128; ++i)
|
||||||
ioctl(fd, RNDADDTOENTCNT, &count);
|
ioctl(fd, RNDADDTOENTCNT, &count);
|
||||||
|
|||||||
@@ -2,27 +2,29 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 Google LLC
|
* Copyright 2018 Google LLC
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/types.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <poll.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <errno.h>
|
#include <sys/stat.h>
|
||||||
#include <string.h>
|
#include <sys/types.h>
|
||||||
#include <poll.h>
|
|
||||||
#include <openssl/bio.h>
|
|
||||||
#include <openssl/err.h>
|
|
||||||
#include <openssl/pem.h>
|
|
||||||
#include <openssl/pkcs7.h>
|
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
#include <openssl/md5.h>
|
#include <openssl/md5.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#ifndef __S_IFREG
|
||||||
|
#define __S_IFREG S_IFREG
|
||||||
|
#endif
|
||||||
|
|
||||||
int mount_fs(const char *mount_dir, const char *backing_dir,
|
int mount_fs(const char *mount_dir, const char *backing_dir,
|
||||||
int read_timeout_ms)
|
int read_timeout_ms)
|
||||||
{
|
{
|
||||||
@@ -184,7 +186,7 @@ int open_commands_file(const char *mount_dir)
|
|||||||
|
|
||||||
snprintf(cmd_file, ARRAY_SIZE(cmd_file),
|
snprintf(cmd_file, ARRAY_SIZE(cmd_file),
|
||||||
"%s/%s", mount_dir, INCFS_PENDING_READS_FILENAME);
|
"%s/%s", mount_dir, INCFS_PENDING_READS_FILENAME);
|
||||||
cmd_fd = open(cmd_file, O_RDONLY);
|
cmd_fd = open(cmd_file, O_RDONLY | O_CLOEXEC);
|
||||||
|
|
||||||
if (cmd_fd < 0)
|
if (cmd_fd < 0)
|
||||||
perror("Can't open commands file");
|
perror("Can't open commands file");
|
||||||
@@ -197,7 +199,7 @@ int open_log_file(const char *mount_dir)
|
|||||||
int cmd_fd;
|
int cmd_fd;
|
||||||
|
|
||||||
snprintf(cmd_file, ARRAY_SIZE(cmd_file), "%s/.log", mount_dir);
|
snprintf(cmd_file, ARRAY_SIZE(cmd_file), "%s/.log", mount_dir);
|
||||||
cmd_fd = open(cmd_file, O_RDWR);
|
cmd_fd = open(cmd_file, O_RDWR | O_CLOEXEC);
|
||||||
if (cmd_fd < 0)
|
if (cmd_fd < 0)
|
||||||
perror("Can't open log file");
|
perror("Can't open log file");
|
||||||
return cmd_fd;
|
return cmd_fd;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "../../include/uapi/linux/incrementalfs.h"
|
#include <include/uapi/linux/incrementalfs.h>
|
||||||
|
|
||||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user