How to run unit tests on a C project (like an Operating System) that redefines built-in functions?

I’m learning about Operating Systems by using the OS161 teaching kernel that was developed by Harvard and used by several online courses and MOOCs like the one I’m taking.

I’m keen to do some of the exercises for OS161; however, before I begin, I’ve been trying to set up C unit tests for any code that I eventually write. In the past, I’ve used GoogleTest and CMake in my own C projects, which is pretty straightforward to set up but I haven’t been able to get this combo to work for the OS161 kernel so far.

The following questions that I have are platform and testing framework agnostic but in the interest of being precise, I have been trying to set up CMake so that it is able to run a simple Catch2 unit test. I’m use CLion as my test runner to make life easy and everything is running on Ubuntu 18.04.

My goal isn’t to perfectly build and run the kernel via CMake (this would be a bonus) as I am happy to use the BSD Makefiles that come with the kernel for that. My goal is to use CMake and Catch2/GoogleTest to run unit tests on C code that I write for the OS161 kernel.

I believe the main problems I face with setting up CMake and Catch2/GoogleTest are as follows:

  • The OS161 kernel redefines several functions that are builtin to the GCC compiler. As such, when I try to build the entire OS161 project (to run a unit test), I get the following warning despite my efforts to use the -fno-builtin flag:
/home/p4t/learning-os/os161-catch/kern/include/lib.h:142:8: warning: conflicting types for built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
 size_t strlen(const char *str);
        ^~~~~~

How should I edit my CMakeLists.txt file to resolve the above error?

  • The other related problem that I face is that as mentioned above, OS161 (and OS kernels in general) do not use the C standard library (libc). As such when compiling, I believe I also need to use the -nostdlib flag to ensure there’s no conflict between the utility methods defined by the kernel itself with libc. However, the dilemma that I face is that I believe that Catch2 and GoogleTest do require libc to run properly.

How should I structure my CMakeLists.txt accordingly so that libc is available to Catch2 so my unit tests can run properly but not to the OS161 kernel?

My current attempt is as follows. The full repository containing this attempt can be found here:

My root CMakeLists.txt file contains the following:

cmake_minimum_required(VERSION 3.20)
project(os161 C)

set(CMAKE_CXX_STANDARD 11)

set(GCC_COMPILE_FLAGS -nostdlib -fno-builtin)

SET(CMAKE_BUILD_TYPE Debug)

include_directories(kern/include)
include_directories(kern/dev)
include_directories(kern/compile/ASST0)
include_directories(kern/compile/ASST0/includelinks)
include_directories(kern/compile)

include_directories(userland/include)

file(GLOB_RECURSE INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/*.h")
file(GLOB_RECURSE SOURCE_FILES "${PROJECT_SOURCE_DIR}/*.c")

add_executable (os161 ${INCLUDE_DIRECTORIES} ${SOURCE_FILES})

# Enabling tests
enable_testing()

add_subdirectory(test/unit)

I also created a test directory where I intend to place all my unit tests. Below is it’s structure:

test
└── unit
    ├── CMakeLists.txt
    └── kern
        └── main
            └── test_main.cpp

In the test/unit/CMakeLists.txt file, we have the following:

project(os161-test)

# These are compiler flags specific for running tests.
set(GCC_COMPILE_FLAGS_TEST -fno-builtin)

# Download Catch
include(FetchContent)
FetchContent_Declare(
        Catch2
        GIT_REPOSITORY https://github.com/catchorg/Catch2.git
        GIT_TAG        v2.13.1)

FetchContent_MakeAvailable(Catch2)

add_executable(test_main kern/main/test_main.cpp)

target_link_libraries(test_main Catch2::Catch2)
target_compile_options(test_main PRIVATE ${GCC_COMPILE_FLAGS} ${GCC_COMPILE_FLAGS_TEST})
add_test(test_main test_main)

As we can see from above, I’ve currently only created a single unit test called test_main. As shown below, inside test_main.cpp I have a simple “hello world” example unit test from [the
Catch2 tutorial][7].

#include <catch2/catch.hpp>

unsigned int Factorial( unsigned int number ) {
    return number <= 1 ? number : Factorial(number-1)*number;
}

TEST_CASE( "Factorials are computed", "[factorial]" ) {
    REQUIRE( Factorial(1) == 1 );
    REQUIRE( Factorial(2) == 2 );
    REQUIRE( Factorial(3) == 6 );
    REQUIRE( Factorial(10) == 3628800 );
}

Currently, when I try to run the unit tests via the CLion test runner, CMake executes the following build command first:

cmake --build /home/p4t/learning-os/os161-catch/cmake-build-debug --target all

Below are the corresponding errors and warnings for the above command:

====================[ Build | all | Debug ]=====================================
/home/p4t/.cache/JetBrains/RemoteDev/dist/78d7fbfd32516_CLion-221.4165.77/bin/cmake/linux/bin/cmake --build /home/p4t/learning-os/os161-catch/cmake-build-debug --target all
[1/351] Building C object CMakeFiles/os161.dir/kern/arch/mips/syscall/syscall.c.o
FAILED: CMakeFiles/os161.dir/kern/arch/mips/syscall/syscall.c.o 
/usr/bin/cc  -I/home/p4t/learning-os/os161-catch/kern/include -I/home/p4t/learning-os/os161-catch/kern/dev -I/home/p4t/learning-os/os161-catch/kern/compile/ASST0 -I/home/p4t/learning-os/os161-catch/kern/compile/ASST0/includelinks -I/home/p4t/learning-os/os161-catch/kern/compile -I/home/p4t/learning-os/os161-catch/userland/include -g -MD -MT CMakeFiles/os161.dir/kern/arch/mips/syscall/syscall.c.o -MF CMakeFiles/os161.dir/kern/arch/mips/syscall/syscall.c.o.d -o CMakeFiles/os161.dir/kern/arch/mips/syscall/syscall.c.o -c /home/p4t/learning-os/os161-catch/kern/arch/mips/syscall/syscall.c
In file included from /home/p4t/learning-os/os161-catch/kern/arch/mips/syscall/syscall.c:33:0:
/home/p4t/learning-os/os161-catch/kern/include/lib.h:142:8: warning: conflicting types for built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
 size_t strlen(const char *str);
        ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:151:7: warning: conflicting types for built-in function ‘memcpy’ [-Wbuiltin-declaration-mismatch]
 void *memcpy(void *dest, const void *src, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:152:7: warning: conflicting types for built-in function ‘memmove’ [-Wbuiltin-declaration-mismatch]
 void *memmove(void *dest, const void *src, size_t len);
       ^~~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:153:7: warning: conflicting types for built-in function ‘memset’ [-Wbuiltin-declaration-mismatch]
 void *memset(void *block, int ch, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:154:6: warning: conflicting types for built-in function ‘bzero’ [-Wbuiltin-declaration-mismatch]
 void bzero(void *ptr, size_t len);
      ^~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:157:5: warning: conflicting types for built-in function ‘snprintf’ [-Wbuiltin-declaration-mismatch]
 int snprintf(char *buf, size_t maxlen, const char *fmt, ...) __PF(3,4);
     ^~~~~~~~
In file included from /home/p4t/learning-os/os161-catch/kern/include/current.h:66:0,
                 from /home/p4t/learning-os/os161-catch/kern/arch/mips/syscall/syscall.c:36:
/home/p4t/learning-os/os161-catch/kern/compile/ASST0/includelinks/machine/current.h:63:25: error: invalid register name for ‘curthread’
 register struct thread *curthread __asm("$23"); /* s7 register */
                         ^~~~~~~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/syscall/syscall.c: In function ‘syscall’:
/home/p4t/learning-os/os161-catch/kern/arch/mips/syscall/syscall.c:108:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   err = sys___time((userptr_t)tf->tf_a0,
                    ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/syscall/syscall.c:109:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      (userptr_t)tf->tf_a1);
      ^
[2/351] Building C object CMakeFiles/os161.dir/kern/arch/mips/locore/trap.c.o
FAILED: CMakeFiles/os161.dir/kern/arch/mips/locore/trap.c.o 
/usr/bin/cc  -I/home/p4t/learning-os/os161-catch/kern/include -I/home/p4t/learning-os/os161-catch/kern/dev -I/home/p4t/learning-os/os161-catch/kern/compile/ASST0 -I/home/p4t/learning-os/os161-catch/kern/compile/ASST0/includelinks -I/home/p4t/learning-os/os161-catch/kern/compile -I/home/p4t/learning-os/os161-catch/userland/include -g -MD -MT CMakeFiles/os161.dir/kern/arch/mips/locore/trap.c.o -MF CMakeFiles/os161.dir/kern/arch/mips/locore/trap.c.o.d -o CMakeFiles/os161.dir/kern/arch/mips/locore/trap.c.o -c /home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c
In file included from /home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:32:0:
/home/p4t/learning-os/os161-catch/kern/include/lib.h:142:8: warning: conflicting types for built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
 size_t strlen(const char *str);
        ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:151:7: warning: conflicting types for built-in function ‘memcpy’ [-Wbuiltin-declaration-mismatch]
 void *memcpy(void *dest, const void *src, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:152:7: warning: conflicting types for built-in function ‘memmove’ [-Wbuiltin-declaration-mismatch]
 void *memmove(void *dest, const void *src, size_t len);
       ^~~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:153:7: warning: conflicting types for built-in function ‘memset’ [-Wbuiltin-declaration-mismatch]
 void *memset(void *block, int ch, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:154:6: warning: conflicting types for built-in function ‘bzero’ [-Wbuiltin-declaration-mismatch]
 void bzero(void *ptr, size_t len);
      ^~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:157:5: warning: conflicting types for built-in function ‘snprintf’ [-Wbuiltin-declaration-mismatch]
 int snprintf(char *buf, size_t maxlen, const char *fmt, ...) __PF(3,4);
     ^~~~~~~~
In file included from /home/p4t/learning-os/os161-catch/kern/include/current.h:66:0,
                 from /home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:38:
/home/p4t/learning-os/os161-catch/kern/compile/ASST0/includelinks/machine/current.h:63:25: error: invalid register name for ‘curthread’
 register struct thread *curthread __asm("$23"); /* s7 register */
                         ^~~~~~~~~
In file included from /home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:32:0:
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c: In function ‘mips_trap’:
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:147:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   KASSERT((vaddr_t)tf > (vaddr_t)curthread->t_stack);
           ^
/home/p4t/learning-os/os161-catch/kern/include/lib.h:66:4: note: in definition of macro ‘KASSERT’
  ((expr) ? (void)0 : badassert(#expr, __FILE__, __LINE__, __func__))
    ^~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:147:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   KASSERT((vaddr_t)tf > (vaddr_t)curthread->t_stack);
                         ^
/home/p4t/learning-os/os161-catch/kern/include/lib.h:66:4: note: in definition of macro ‘KASSERT’
  ((expr) ? (void)0 : badassert(#expr, __FILE__, __LINE__, __func__))
    ^~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:148:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   KASSERT((vaddr_t)tf < (vaddr_t)(curthread->t_stack
           ^
/home/p4t/learning-os/os161-catch/kern/include/lib.h:66:4: note: in definition of macro ‘KASSERT’
  ((expr) ? (void)0 : badassert(#expr, __FILE__, __LINE__, __func__))
    ^~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:148:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   KASSERT((vaddr_t)tf < (vaddr_t)(curthread->t_stack
                         ^
/home/p4t/learning-os/os161-catch/kern/include/lib.h:66:4: note: in definition of macro ‘KASSERT’
  ((expr) ? (void)0 : badassert(#expr, __FILE__, __LINE__, __func__))
    ^~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:302:16: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   tf->tf_epc = (vaddr_t) curthread->t_machdep.tm_badfaultfunc;
                ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:335:33: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  cputhreads[curcpu->c_number] = (vaddr_t)curthread;
                                 ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:336:32: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  cpustacks[curcpu->c_number] = (vaddr_t)curthread->t_stack + STACK_SIZE;
                                ^
In file included from /home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:32:0:
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:347:52: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  KASSERT(SAME_STACK(cpustacks[curcpu->c_number]-1, (vaddr_t)tf));
                                                    ^
/home/p4t/learning-os/os161-catch/kern/include/lib.h:66:4: note: in definition of macro ‘KASSERT’
  ((expr) ? (void)0 : badassert(#expr, __FILE__, __LINE__, __func__))
    ^~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:347:10: note: in expansion of macro ‘SAME_STACK’
  KASSERT(SAME_STACK(cpustacks[curcpu->c_number]-1, (vaddr_t)tf));
          ^~~~~~~~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c: In function ‘mips_usermode’:
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:380:33: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  cputhreads[curcpu->c_number] = (vaddr_t)curthread;
                                 ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:381:32: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  cpustacks[curcpu->c_number] = (vaddr_t)curthread->t_stack + STACK_SIZE;
                                ^
In file included from /home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:32:0:
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:398:52: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  KASSERT(SAME_STACK(cpustacks[curcpu->c_number]-1, (vaddr_t)tf));
                                                    ^
/home/p4t/learning-os/os161-catch/kern/include/lib.h:66:4: note: in definition of macro ‘KASSERT’
  ((expr) ? (void)0 : badassert(#expr, __FILE__, __LINE__, __func__))
    ^~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:398:10: note: in expansion of macro ‘SAME_STACK’
  KASSERT(SAME_STACK(cpustacks[curcpu->c_number]-1, (vaddr_t)tf));
          ^~~~~~~~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c: In function ‘enter_new_process’:
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:433:13: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  tf.tf_a1 = (vaddr_t)argv;
             ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/locore/trap.c:434:13: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  tf.tf_a2 = (vaddr_t)env;
             ^
[3/351] Building C object CMakeFiles/os161.dir/kern/arch/mips/vm/dumbvm.c.o
FAILED: CMakeFiles/os161.dir/kern/arch/mips/vm/dumbvm.c.o 
/usr/bin/cc  -I/home/p4t/learning-os/os161-catch/kern/include -I/home/p4t/learning-os/os161-catch/kern/dev -I/home/p4t/learning-os/os161-catch/kern/compile/ASST0 -I/home/p4t/learning-os/os161-catch/kern/compile/ASST0/includelinks -I/home/p4t/learning-os/os161-catch/kern/compile -I/home/p4t/learning-os/os161-catch/userland/include -g -MD -MT CMakeFiles/os161.dir/kern/arch/mips/vm/dumbvm.c.o -MF CMakeFiles/os161.dir/kern/arch/mips/vm/dumbvm.c.o.d -o CMakeFiles/os161.dir/kern/arch/mips/vm/dumbvm.c.o -c /home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c
In file included from /home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c:32:0:
/home/p4t/learning-os/os161-catch/kern/include/lib.h:142:8: warning: conflicting types for built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
 size_t strlen(const char *str);
        ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:151:7: warning: conflicting types for built-in function ‘memcpy’ [-Wbuiltin-declaration-mismatch]
 void *memcpy(void *dest, const void *src, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:152:7: warning: conflicting types for built-in function ‘memmove’ [-Wbuiltin-declaration-mismatch]
 void *memmove(void *dest, const void *src, size_t len);
       ^~~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:153:7: warning: conflicting types for built-in function ‘memset’ [-Wbuiltin-declaration-mismatch]
 void *memset(void *block, int ch, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:154:6: warning: conflicting types for built-in function ‘bzero’ [-Wbuiltin-declaration-mismatch]
 void bzero(void *ptr, size_t len);
      ^~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:157:5: warning: conflicting types for built-in function ‘snprintf’ [-Wbuiltin-declaration-mismatch]
 int snprintf(char *buf, size_t maxlen, const char *fmt, ...) __PF(3,4);
     ^~~~~~~~
In file included from /home/p4t/learning-os/os161-catch/kern/include/current.h:66:0,
                 from /home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c:37:
/home/p4t/learning-os/os161-catch/kern/compile/ASST0/includelinks/machine/current.h:63:25: error: invalid register name for ‘curthread’
 register struct thread *curthread __asm("$23"); /* s7 register */
                         ^~~~~~~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c: In function ‘as_zero_region’:
/home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c:355:8: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  bzero((void *)PADDR_TO_KVADDR(paddr), npages * PAGE_SIZE);
        ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c: In function ‘as_copy’:
/home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c:428:10: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  memmove((void *)PADDR_TO_KVADDR(new->as_pbase1),
          ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c:429:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   (const void *)PADDR_TO_KVADDR(old->as_pbase1),
   ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c:432:10: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  memmove((void *)PADDR_TO_KVADDR(new->as_pbase2),
          ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c:433:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   (const void *)PADDR_TO_KVADDR(old->as_pbase2),
   ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c:436:10: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  memmove((void *)PADDR_TO_KVADDR(new->as_stackpbase),
          ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/vm/dumbvm.c:437:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   (const void *)PADDR_TO_KVADDR(old->as_stackpbase),
   ^
[4/351] Building C object CMakeFiles/os161.dir/kern/arch/mips/thread/thread_machdep.c.o
In file included from /home/p4t/learning-os/os161-catch/kern/arch/mips/thread/thread_machdep.c:35:0:
/home/p4t/learning-os/os161-catch/kern/include/lib.h:142:8: warning: conflicting types for built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
 size_t strlen(const char *str);
        ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:151:7: warning: conflicting types for built-in function ‘memcpy’ [-Wbuiltin-declaration-mismatch]
 void *memcpy(void *dest, const void *src, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:152:7: warning: conflicting types for built-in function ‘memmove’ [-Wbuiltin-declaration-mismatch]
 void *memmove(void *dest, const void *src, size_t len);
       ^~~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:153:7: warning: conflicting types for built-in function ‘memset’ [-Wbuiltin-declaration-mismatch]
 void *memset(void *block, int ch, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:154:6: warning: conflicting types for built-in function ‘bzero’ [-Wbuiltin-declaration-mismatch]
 void bzero(void *ptr, size_t len);
      ^~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:157:5: warning: conflicting types for built-in function ‘snprintf’ [-Wbuiltin-declaration-mismatch]
 int snprintf(char *buf, size_t maxlen, const char *fmt, ...) __PF(3,4);
     ^~~~~~~~
[5/351] Building C object CMakeFiles/os161.dir/kern/arch/mips/vm/ram.c.o
In file included from /home/p4t/learning-os/os161-catch/kern/arch/mips/vm/ram.c:31:0:
/home/p4t/learning-os/os161-catch/kern/include/lib.h:142:8: warning: conflicting types for built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
 size_t strlen(const char *str);
        ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:151:7: warning: conflicting types for built-in function ‘memcpy’ [-Wbuiltin-declaration-mismatch]
 void *memcpy(void *dest, const void *src, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:152:7: warning: conflicting types for built-in function ‘memmove’ [-Wbuiltin-declaration-mismatch]
 void *memmove(void *dest, const void *src, size_t len);
       ^~~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:153:7: warning: conflicting types for built-in function ‘memset’ [-Wbuiltin-declaration-mismatch]
 void *memset(void *block, int ch, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:154:6: warning: conflicting types for built-in function ‘bzero’ [-Wbuiltin-declaration-mismatch]
 void bzero(void *ptr, size_t len);
      ^~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:157:5: warning: conflicting types for built-in function ‘snprintf’ [-Wbuiltin-declaration-mismatch]
 int snprintf(char *buf, size_t maxlen, const char *fmt, ...) __PF(3,4);
     ^~~~~~~~
[6/351] Building C object CMakeFiles/os161.dir/kern/arch/mips/thread/cpu.c.o
FAILED: CMakeFiles/os161.dir/kern/arch/mips/thread/cpu.c.o 
/usr/bin/cc  -I/home/p4t/learning-os/os161-catch/kern/include -I/home/p4t/learning-os/os161-catch/kern/dev -I/home/p4t/learning-os/os161-catch/kern/compile/ASST0 -I/home/p4t/learning-os/os161-catch/kern/compile/ASST0/includelinks -I/home/p4t/learning-os/os161-catch/kern/compile -I/home/p4t/learning-os/os161-catch/userland/include -g -MD -MT CMakeFiles/os161.dir/kern/arch/mips/thread/cpu.c.o -MF CMakeFiles/os161.dir/kern/arch/mips/thread/cpu.c.o.d -o CMakeFiles/os161.dir/kern/arch/mips/thread/cpu.c.o -c /home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c
In file included from /home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:35:0:
/home/p4t/learning-os/os161-catch/kern/include/lib.h:142:8: warning: conflicting types for built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
 size_t strlen(const char *str);
        ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:151:7: warning: conflicting types for built-in function ‘memcpy’ [-Wbuiltin-declaration-mismatch]
 void *memcpy(void *dest, const void *src, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:152:7: warning: conflicting types for built-in function ‘memmove’ [-Wbuiltin-declaration-mismatch]
 void *memmove(void *dest, const void *src, size_t len);
       ^~~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:153:7: warning: conflicting types for built-in function ‘memset’ [-Wbuiltin-declaration-mismatch]
 void *memset(void *block, int ch, size_t len);
       ^~~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:154:6: warning: conflicting types for built-in function ‘bzero’ [-Wbuiltin-declaration-mismatch]
 void bzero(void *ptr, size_t len);
      ^~~~~
/home/p4t/learning-os/os161-catch/kern/include/lib.h:157:5: warning: conflicting types for built-in function ‘snprintf’ [-Wbuiltin-declaration-mismatch]
 int snprintf(char *buf, size_t maxlen, const char *fmt, ...) __PF(3,4);
     ^~~~~~~~
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c: In function ‘cpu_machdep_init’:
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:92:18: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   stackpointer = (vaddr_t) c->c_curthread->t_stack;
                  ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:97:29: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   cputhreads[c->c_number] = (vaddr_t)c->c_curthread;
                             ^
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c: Assembler messages:
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:119: Error: no such instruction: `mfc0 %eax,$15'
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:129: Error: expected comma after "push"
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:129: Error: expected comma after "mips32"
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:129: Error: no such instruction: `mfc0 %eax,$15,1'
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:129: Error: expected comma after "pop"
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:143: Error: expected comma after "push"
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:143: Error: expected comma after "mips32"
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:143: Error: no such instruction: `mfc0 %eax,$15,2'
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:143: Error: expected comma after "pop"
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:214: Error: no such instruction: `mfc0 %eax,$12'
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:216: Error: no such instruction: `mtc0 %eax,$12'
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:227: Error: no such instruction: `mfc0 %eax,$12'
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:229: Error: no such instruction: `mtc0 %eax,$12'
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:241: Error: no such instruction: `mfc0 %eax,$12'
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:244: Error: no such instruction: `mtc0 %eax,$12'
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:246: Error: no such instruction: `mtc0 %eax,$12'
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:280: Error: expected comma after "push"
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:280: Error: expected comma after "mips32"
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:280: Error: expected comma after "volatile"
/home/p4t/learning-os/os161-catch/kern/arch/mips/thread/cpu.c:280: Error: expected comma after "pop"
ninja: build stopped: subcommand failed

As mentioned earlier, I’m aware that the first error regarding conflicting types for built-in function ‘strlen’ is down to the fact that OS161 redefines this function and others in kern/include/lib.h as shown below:

...
size_t strlen(const char *str);
int strcmp(const char *str1, const char *str2);
...

However, in my CMakeLists.txt file, I am already using the -fno-builtin compiler flag so I’m not entirely sure what else I need to do.

What changes do I need to make in CMakeLists.txt in order to run unit tests on C code that I write for the OS161 kernel? As mentioned earlier, here is the full repository of the attempts that I’ve made for easier viewing.