[Assignment-7] cleanup
This commit is contained in:
parent
c5695837a5
commit
d40a4f26d1
6 changed files with 0 additions and 202 deletions
|
@ -1,81 +0,0 @@
|
|||
# Makefile for building the application
|
||||
# Use:
|
||||
# make - compiles both release and test binaries
|
||||
# make release - compiles and runs the release binary
|
||||
# make test - compiles and runs the test binary
|
||||
# make clean - deletes all binaries in build/bin
|
||||
# make cleaner - deltes the whole build directory
|
||||
|
||||
# Compiler
|
||||
CC = clang
|
||||
CFLAGS = -Wall -Wextra -Werror -I$(ENCLAVE_DIR) -I$(APP_DIR)
|
||||
LDFLAGS =
|
||||
|
||||
# Directories
|
||||
SRC_DIR = src
|
||||
LIB_DIR = lib
|
||||
TEST_DIR = test
|
||||
APP_DIR = $(SRC_DIR)/app
|
||||
ENCLAVE_DIR = $(SRC_DIR)/enclave
|
||||
BUILD_DIR = build
|
||||
OBJ_DIR = $(BUILD_DIR)/obj
|
||||
BIN_DIR = $(BUILD_DIR)/bin
|
||||
|
||||
# Source files
|
||||
LIB_SRCS = $(wildcard $(LIB_DIR)/*.c)
|
||||
APP_SRCS = $(wildcard $(APP_DIR)/*.c) $(wildcard $(ENCLAVE_DIR)/*.c)
|
||||
TEST_SRCS = $(wildcard $(TEST_DIR)/*.c)
|
||||
|
||||
# Object files
|
||||
LIB_OBJS = $(LIB_SRCS:$(LIB_DIR)/%.c=$(OBJ_DIR)/lib/%.o)
|
||||
APP_OBJS = $(APP_SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/src/%.o)
|
||||
TEST_OBJS = $(TEST_SRCS:$(TEST_DIR)/%.c=$(OBJ_DIR)/test/%.o)
|
||||
|
||||
# Binaries
|
||||
RELEASE_BIN = $(BIN_DIR)/release
|
||||
TEST_BIN = $(BIN_DIR)/test
|
||||
|
||||
$(RELEASE_BIN): $(LIB_OBJS) $(APP_OBJS)
|
||||
@mkdir -p $(BIN_DIR)
|
||||
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
|
||||
|
||||
$(TEST_BIN): $(LIB_OBJS) $(TEST_OBJS)
|
||||
@mkdir -p $(BIN_DIR)
|
||||
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
|
||||
|
||||
$(OBJ_DIR)/lib/%.o: $(LIB_DIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/src/%.o: $(SRC_DIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/test/%.o: $(TEST_DIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
# Targets
|
||||
.PHONY: all clean release test
|
||||
|
||||
all: release test
|
||||
|
||||
release: $(RELEASE_BIN) run_release
|
||||
|
||||
run_release:
|
||||
@echo "RUNNING RELEASE"
|
||||
@./$(RELEASE_BIN)
|
||||
|
||||
test: $(TEST_BIN) run_test
|
||||
|
||||
run_test:
|
||||
@echo "RUNNING TESTS"
|
||||
@./$(TEST_BIN)
|
||||
|
||||
clean:
|
||||
@echo "Deleting binaries"
|
||||
@rm -rf $(BIN_DIR)
|
||||
|
||||
cleaner:
|
||||
@echo "Deleting builds"
|
||||
@rm -rf $(BUILD_DIR)
|
|
@ -1,16 +0,0 @@
|
|||
#include "framework_test.h"
|
||||
|
||||
bool test_function_true() {
|
||||
return assert_true(false, "Test function true");
|
||||
}
|
||||
|
||||
bool test_function_false() {
|
||||
return assert_false(false, "Reason why it failed");
|
||||
}
|
||||
|
||||
void framework_test() {
|
||||
start_tests("Test Group Name");
|
||||
run_test("Test Name", test_function_true);
|
||||
run_test("Test Name", test_function_false);
|
||||
end_tests();
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef CRYPTO_FRAMEWORK_TEST_H
|
||||
#define CRYPTO_FRAMEWORK_TEST_H
|
||||
|
||||
#include "mini_test.h"
|
||||
|
||||
void framework_test();
|
||||
|
||||
#endif //CRYPTO_FRAMEWORK_TEST_H
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
#include "framework_test.h"
|
||||
|
||||
int main() {
|
||||
// Tests
|
||||
framework_test();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
#include "mini_test.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
|
||||
#define RESET_COLOR "\x1b[0m"
|
||||
#define RED_COLOR "\x1b[31m"
|
||||
#define GREEN_COLOR "\x1b[32m"
|
||||
#define ORANGE_COLOR "\x1b[33m"
|
||||
#define BEGIN_FAT_TEXT "\033[1m"
|
||||
#define END_FAT_TEXT "\033[0m"
|
||||
|
||||
static int total_tests = 0;
|
||||
static int passed_tests = 0;
|
||||
static char *group;
|
||||
|
||||
void start_tests(char *group_name) {
|
||||
group = group_name;
|
||||
total_tests = 0;
|
||||
passed_tests = 0;
|
||||
printf("Starting tests " BEGIN_FAT_TEXT "%s" END_FAT_TEXT "...\n", group);
|
||||
}
|
||||
|
||||
void end_tests() {
|
||||
if (passed_tests == total_tests) {
|
||||
printf(GREEN_COLOR "[%d/%d] Tests passed" RESET_COLOR "\n", passed_tests, total_tests);
|
||||
} else if (passed_tests == 0) {
|
||||
printf(RED_COLOR "[%d/%d] Tests passed" RESET_COLOR "\n", passed_tests, total_tests);
|
||||
} else {
|
||||
printf(ORANGE_COLOR "[%d/%d] Tests passed" RESET_COLOR "\n", passed_tests, total_tests);
|
||||
}
|
||||
}
|
||||
|
||||
void run_test(const char *test_name, bool (*test_fn)(void)) {
|
||||
total_tests++;
|
||||
printf("\tTesting %s... ", test_name);
|
||||
clock_t start, end;
|
||||
start = clock();
|
||||
bool result = test_fn();
|
||||
end = clock();
|
||||
double time_passed = ((double)(end - start)) / CLOCKS_PER_SEC;
|
||||
if (result) {
|
||||
printf(GREEN_COLOR "[✓] %.4fs" RESET_COLOR "\n", time_passed);
|
||||
passed_tests++;
|
||||
} else {
|
||||
printf(RED_COLOR "" RESET_COLOR "\n");
|
||||
}
|
||||
}
|
||||
|
||||
bool assert_true(bool condition, const char *message, ...) {
|
||||
if (!condition) {
|
||||
printf(RED_COLOR "[X] Assertion failed: " RESET_COLOR);
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
vprintf(message, args);
|
||||
va_end(args);
|
||||
printf(" ");
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
bool assert_false(bool condition, const char *message, ...) {
|
||||
if (condition) {
|
||||
printf(RED_COLOR "[X] Assertion failed: " RESET_COLOR);
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
vprintf(message, args);
|
||||
va_end(args);
|
||||
printf(" ");
|
||||
}
|
||||
return !condition;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef CRYPTO_MINI_TEST_H
|
||||
#define CRYPTO_MINI_TEST_H
|
||||
#include <stdbool.h>
|
||||
|
||||
void start_tests(char *group_name);
|
||||
|
||||
void end_tests();
|
||||
|
||||
void run_test(const char *tests_name, bool (*test_fn)(void));
|
||||
|
||||
bool assert_true(bool condition, const char *message, ...);
|
||||
|
||||
bool assert_false(bool condition, const char *message, ...);
|
||||
|
||||
#endif //CRYPTO_MINI_TEST_H
|
Loading…
Reference in a new issue