aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2016-07-30 23:17:12 +0200
committerAlex Auvolat <alex@adnab.me>2016-07-30 23:17:12 +0200
commitf58f65c30de315d4419f69a92a708cbed797ff37 (patch)
treeefaaa82089523dc0f7a3b9a6ab4c963550f9b241
parentfa5327d4cc5e47656326b8c0c55d23cd71b04462 (diff)
downloadkogata-f58f65c30de315d4419f69a92a708cbed797ff37.tar.gz
kogata-f58f65c30de315d4419f69a92a708cbed797ff37.zip
Release mode (enables some optimizations) ; fix tests.
-rw-r--r--Makefile4
-rw-r--r--bam.lua111
-rwxr-xr-xmake_cdrom.sh29
-rw-r--r--res/fonts/bam.lua36
-rw-r--r--res/keymaps/bam.lua24
-rw-r--r--src/bin/bam.lua37
-rw-r--r--src/common/bam.lua16
-rw-r--r--src/common/include/proto/fs.h6
-rw-r--r--src/kernel/bam.lua34
-rw-r--r--src/kernel/core/kmain.c8
-rw-r--r--src/kernel/user/syscall.c1
-rw-r--r--src/lib/bam.lua24
-rw-r--r--src/lib/libc/syscall.c7
-rw-r--r--src/sysbin/bam.lua39
-rw-r--r--src/tests/ktests/bam.lua61
-rwxr-xr-xsrc/tests/ktests/run_qemu_test.sh3
-rw-r--r--src/tests/slab_test/bam.lua19
-rw-r--r--src/tests/slab_test/slab_test.c2
-rw-r--r--src/tests/utests/bam.lua37
-rw-r--r--src/tests/utests/chan1/test.c18
-rw-r--r--src/tests/utests/chan2/test.c50
-rw-r--r--src/tests/utests/fs1/test.c18
-rw-r--r--src/tests/utests/fs2/test.c16
-rw-r--r--src/tests/utests/malloc/test.c8
-rwxr-xr-xsrc/tests/utests/run_qemu_test.sh5
-rw-r--r--src/tests/utests/subfs/test.c18
26 files changed, 362 insertions, 269 deletions
diff --git a/Makefile b/Makefile
index f7a291f..49189ad 100644
--- a/Makefile
+++ b/Makefile
@@ -24,10 +24,10 @@ run_tests:
bam test
run_qemu: all
- qemu-system-i386 -cdrom cdrom.iso -serial stdio -m 12 </dev/null
+ qemu-system-i386 -cdrom cdrom.dev.iso -serial stdio -m 12 </dev/null
run_qemu_debug: all
- qemu-system-i386 -cdrom cdrom.iso -serial stdio -m 12 -s -S </dev/null & \
+ qemu-system-i386 -cdrom cdrom.dev.iso -serial stdio -m 12 -s -S </dev/null & \
(sleep 0.1; gdb src/kernel/kernel.bin -x gdb_cmd)
run_bochs_debug: all
diff --git a/bam.lua b/bam.lua
index 1880f6d..d9721f1 100644
--- a/bam.lua
+++ b/bam.lua
@@ -2,20 +2,24 @@
-- Redefine output function to put everything in build/
--
-function BuildOutput(settings, fname)
- if fname:sub(1, 4) == "src/" or fname:sub(1, 4) == "res/" then
- fname = fname:sub(5)
+function BuildOutput(mode)
+ local basepath = mode and ("build/" .. mode) or "build"
+
+ return function (settings, fname)
+ if fname:sub(1, 4) == "src/" or fname:sub(1, 4) == "res/" then
+ fname = fname:sub(5)
+ end
+ local out = PathJoin(basepath, PathBase(fname) .. settings.config_ext)
+ return out
end
- local out = PathJoin("build", PathBase(fname) .. settings.config_ext)
- return out
end
--
-- Define custom settings
--
-host_settings = NewSettings()
-common_settings = NewSettings()
+local host_settings = NewSettings()
+local common_settings = NewSettings()
if os.getenv('CC') and string.match(os.getenv('CC'), '.*analyzer$') then
print("Detected clang-analyzer")
@@ -35,7 +39,7 @@ else
end
-host_settings.cc.Output = BuildOutput
+host_settings.cc.Output = BuildOutput(nil)
host_settings.cc.extension = ".host.o"
host_settings.cc.includes:Add("src/lib/include/proto",
"src/common/include")
@@ -43,66 +47,97 @@ host_settings.link.extension = ".bin"
common_settings.compile.mappings['s'] = function(settings, input)
- local output = BuildOutput(settings, input) .. settings.cc.extension
+ local output = settings.cc.Output(settings, input) .. settings.cc.extension
AddJob(output, "nasm " .. input,
"nasm -felf -g -o " .. output .. " " .. input)
AddDependency(output, input)
return output
end
-common_settings.cc.Output = BuildOutput
+common_settings.cc.Output = BuildOutput(nil)
common_settings.cc.includes:Add("src/common/include", ".")
common_settings.cc.flags:Add("-m32",
"-ffreestanding",
"-std=gnu99",
"-Wall", "-Wextra", "-Werror",
"-Wno-unused-parameter",
- "-Wno-unused-function",
- "-g", "-O0")
+ "-Wno-unused-function")
common_settings.link.extension = ".bin"
common_settings.link.flags:Add("-ffreestanding",
- "-nostdlib",
- "-O0")
+ "-nostdlib")
common_settings.link.libs:Add("gcc")
-common_settings.link.Output = BuildOutput
+common_settings.link.Output = BuildOutput(nil)
-user_settings = TableDeepCopy(common_settings)
+local user_settings = TableDeepCopy(common_settings)
user_settings.cc.includes:Add('src/lib/include')
+local base_settings = {
+ host_settings = host_settings,
+ common_settings = common_settings,
+ user_settings = user_settings
+}
+
--
-- Require build scripts for all components
--
-require 'src/common/bam'
-require 'src/kernel/bam'
-require 'src/lib/bam'
-require 'src/sysbin/bam'
-require 'src/bin/bam'
+local fonts = require('res/fonts/bam')(base_settings)
+local keymaps = require('res/keymaps/bam')(base_settings)
-require 'res/fonts/bam'
-require 'res/keymaps/bam'
+local function cdrom(name, settings)
+ for _, s in pairs(settings) do
+ s.cc.Output = BuildOutput(name)
+ s.link.Output = BuildOutput(name)
+ end
---
--- Build script for CDROM.iso
---
+ local common = require('src/common/bam')(settings)
+ local kernel = require('src/kernel/bam')(settings, common)
+ local lib = require('src/lib/bam')(settings, common)
+ local sysbin = require('src/sysbin/bam')(settings, lib)
+ local bin = require('src/bin/bam')(settings, lib)
-cdrom = "build/cdrom.iso"
+ if name == "dev" then
+ dev_kernel = kernel
+ end
-AddJob(cdrom, "building ISO", "./make_cdrom.sh")
-AddDependency(cdrom, kernel, sysbin, bin, fonts, keymaps)
+ local cdrom = "cdrom." .. name .. ".iso"
+ AddJob(cdrom, "building ISO", "./make_cdrom.sh " .. name)
+ AddDependency(cdrom, kernel.bin, sysbin, bin, fonts, keymaps)
-DefaultTarget(cdrom)
+ --
+ -- Script for running tests
+ --
---
--- Script for running tests
---
+ local tests = {
+ require('src/tests/slab_test/bam')(settings),
+ require('src/tests/ktests/bam')(settings, common, kernel.obj),
+ require('src/tests/utests/bam')(settings, kernel.bin, lib)
+ }
-tests = {}
+ PseudoTarget("test." .. name, tests)
+
+ return cdrom
+end
+
+
+local dev_settings = TableDeepCopy(base_settings)
+for _, s in pairs(dev_settings) do
+ s.cc.flags:Add("-g", "-O0")
+end
+local dev_cdrom = cdrom("dev", dev_settings)
+
+local rel_settings = TableDeepCopy(base_settings)
+for _, s in pairs(rel_settings) do
+ s.cc.flags:Add("-Os", "-flto")
+ s.link.flags:Add("-Os", "-flto")
+
+ -- Maybee
+ -- s.cc.flags:Add("-ffunction-sections", "-fdata-sections")
+ -- s.link.flags:Add("-Wl,--gc-sections")
+end
+local rel_cdrom = cdrom("rel", rel_settings)
-require 'src/tests/slab_test/bam'
-require 'src/tests/ktests/bam'
-require 'src/tests/utests/bam'
+DefaultTarget(dev_cdrom)
-PseudoTarget("test", tests)
diff --git a/make_cdrom.sh b/make_cdrom.sh
index bbf2a4b..d8302a9 100755
--- a/make_cdrom.sh
+++ b/make_cdrom.sh
@@ -1,5 +1,20 @@
#!/bin/sh
+TY="$1"
+
+echo "Building cdrom type: $TY"
+
+if [ "$TY" != "dev" -a "$TY" != "rel" ]; then
+ print "Invalid build type: $TY, expected dev or rel"
+ exit -1
+fi
+
+if [ "$TY" = "dev" ]; then
+ STRIP="strip --strip-debug"
+else
+ STRIP="strip -s -R .comment -R .gnu.version"
+fi
+
if [ ! -e cdrom/boot/grub/stage2_eltorito ]; then
mkdir -p cdrom/boot/grub
echo "Please copy grub's stage2_eltorito to cdrom/boot/grub."
@@ -8,19 +23,19 @@ fi
# Copy system files to CDROM
-cp build/kernel.bin cdrom/boot; strip --strip-debug cdrom/boot/kernel.bin
-cp build/sysbin/init.bin cdrom/boot; strip --strip-debug cdrom/boot/init.bin
+cp build/$TY/kernel.bin cdrom/boot; $STRIP cdrom/boot/kernel.bin
+cp build/$TY/sysbin/init.bin cdrom/boot; $STRIP cdrom/boot/init.bin
mkdir -p cdrom/sys/bin
for BIN in giosrv.bin login.bin terminal.bin shell.bin; do
- cp build/sysbin/$BIN cdrom/sys/bin
- strip --strip-debug cdrom/sys/bin/$BIN
+ cp build/$TY/sysbin/$BIN cdrom/sys/bin
+ $STRIP cdrom/sys/bin/$BIN
done
mkdir -p cdrom/bin
for BIN in lua.bin luac.bin; do
- cp build/bin/$BIN cdrom/bin
- strip --strip-debug cdrom/bin/$BIN
+ cp build/$TY/bin/$BIN cdrom/bin
+ $STRIP cdrom/bin/$BIN
done
mkdir -p cdrom/sys/fonts
@@ -51,4 +66,4 @@ EOF
genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot \
-boot-load-size 4 -boot-info-table -input-charset ascii \
- -A kogata-os -o cdrom.iso cdrom
+ -A kogata-os -o cdrom.$TY.iso cdrom
diff --git a/res/fonts/bam.lua b/res/fonts/bam.lua
index 04974c4..4ba29d1 100644
--- a/res/fonts/bam.lua
+++ b/res/fonts/bam.lua
@@ -1,19 +1,25 @@
-fonts = {}
+return function(s)
+ local fonts = {}
-for _, file in pairs(Collect('res/fonts/*.s')) do
- local out = BuildOutput(host_settings, PathBase(file)) .. '.bf'
- AddJob(out, "nasm font " .. out, "nasm -o " .. out .. " " .. file)
- AddDependency(out, file)
- table.insert(fonts, out)
-end
+ local BO = s.host_settings.cc.Output
+
+ for _, file in pairs(Collect('res/fonts/*.s')) do
+ local out = BO(s.host_settings, PathBase(file)) .. '.bf'
+ AddJob(out, "nasm font " .. out, "nasm -o " .. out .. " " .. file)
+ AddDependency(out, file)
+ table.insert(fonts, out)
+ end
+
+ for _, file in pairs(Collect('res/fonts/*.c')) do
+ local obj = Compile(s.host_settings, file)
+ local tgt = BO(s.host_settings, PathBase(file) .. '_tmp')
+ local bin = Link(s.host_settings, tgt, obj)
-for _, file in pairs(Collect('res/fonts/*.c')) do
- local obj = Compile(host_settings, file)
- local tgt = BuildOutput(host_settings, PathBase(file) .. '_tmp')
- local bin = Link(host_settings, tgt, obj)
+ local out = BO(s.host_settings, PathBase(file)) .. '.bf'
+ AddJob(out, "call font " .. bin, "./" .. bin .. " > " .. out)
+ AddDependency(out, bin)
+ table.insert(fonts, out)
+ end
- local out = BuildOutput(host_settings, PathBase(file)) .. '.bf'
- AddJob(out, "call font " .. bin, "./" .. bin .. " > " .. out)
- AddDependency(out, bin)
- table.insert(fonts, out)
+ return fonts
end
diff --git a/res/keymaps/bam.lua b/res/keymaps/bam.lua
index 0657abc..7aef6c0 100644
--- a/res/keymaps/bam.lua
+++ b/res/keymaps/bam.lua
@@ -1,12 +1,18 @@
-keymaps = {}
+return function(s)
+ local keymaps = {}
-for _, file in pairs(Collect('res/keymaps/*.c')) do
- local obj = Compile(host_settings, file)
- local tgt = BuildOutput(host_settings, PathBase(file) .. '_tmp')
- local bin = Link(host_settings, tgt, obj)
+ local BO = s.host_settings.cc.Output
- local out = BuildOutput(host_settings, PathBase(file)) .. '.km'
- AddJob(out, "call font " .. bin, "./" .. bin .. " > " .. out)
- AddDependency(out, bin)
- table.insert(keymaps, out)
+ for _, file in pairs(Collect('res/keymaps/*.c')) do
+ local obj = Compile(s.host_settings, file)
+ local tgt = BO(s.host_settings, PathBase(file) .. '_tmp')
+ local bin = Link(s.host_settings, tgt, obj)
+
+ local out = BO(s.host_settings, PathBase(file)) .. '.km'
+ AddJob(out, "call font " .. bin, "./" .. bin .. " > " .. out)
+ AddDependency(out, bin)
+ table.insert(keymaps, out)
+ end
+
+ return keymaps
end
diff --git a/src/bin/bam.lua b/src/bin/bam.lua
index 76b7b2a..d529ece 100644
--- a/src/bin/bam.lua
+++ b/src/bin/bam.lua
@@ -1,23 +1,24 @@
-local function bin_settings(name)
- local s = TableDeepCopy(user_settings)
- s.link.flags:Add("-T src/lib/linker.ld",
- "-Xlinker -Map=build/bin/" .. name .. ".map")
- if name == 'lua' or name == 'luac' then
- s.cc.includes:Add("src/lib/lua")
+return function(s, lib)
+ local function bin_settings(name)
+ local s = TableDeepCopy(s.user_settings)
+ s.link.flags:Add("-T src/lib/linker.ld")
+ if name == 'lua' or name == 'luac' then
+ s.cc.includes:Add("src/lib/lua")
+ end
+ return s
end
- return s
-end
-local function bin_exe(name, deps)
- local s = bin_settings(name)
+ local function bin_exe(name, deps)
+ local s = bin_settings(name)
- local src = Collect('src/bin/' .. name .. '/*.c')
- local obj = Compile(s, src)
+ local src = Collect('src/bin/' .. name .. '/*.c')
+ local obj = Compile(s, src)
- return Link(s, 'bin/' .. name .. ".bin", {obj, deps})
-end
+ return Link(s, 'bin/' .. name .. ".bin", {obj, deps})
+ end
-bin = {
- bin_exe('lua', {liblua}),
- -- bin_exe('luac', {liblua}),
-}
+ return {
+ bin_exe('lua', {lib.liblua}),
+ -- bin_exe('luac', {liblua}),
+ }
+end
diff --git a/src/common/bam.lua b/src/common/bam.lua
index 6d4a29c..77b98c5 100644
--- a/src/common/bam.lua
+++ b/src/common/bam.lua
@@ -1,7 +1,11 @@
-local function lib(name)
- local source = Collect('src/common/' .. name .. '/*.c')
- return Compile(common_settings, source)
-end
+return function(s)
+ local function lib(name)
+ local source = Collect('src/common/' .. name .. '/*.c')
+ return Compile(s.common_settings, source)
+ end
-common_libc = lib('libc')
-common_libkogata = lib('libkogata')
+ return {
+ libc = lib('libc'),
+ libkogata = lib('libkogata')
+ }
+end
diff --git a/src/common/include/proto/fs.h b/src/common/include/proto/fs.h
index e70ff55..49091eb 100644
--- a/src/common/include/proto/fs.h
+++ b/src/common/include/proto/fs.h
@@ -50,9 +50,9 @@ typedef struct {
#define IOCTL_BLOCKDEV_GET_BLOCK_COUNT 41
-#define SEL_READ 0x01
-#define SEL_WRITE 0x02
-#define SEL_ERROR 0x04
+#define SEL_READ (0x01)
+#define SEL_WRITE (0x02)
+#define SEL_ERROR (0x04)
typedef struct {
fd_t fd;
diff --git a/src/kernel/bam.lua b/src/kernel/bam.lua
index 2dc724e..43328e6 100644
--- a/src/kernel/bam.lua
+++ b/src/kernel/bam.lua
@@ -1,19 +1,23 @@
-local kernel_settings = TableDeepCopy(common_settings)
+return function(s, common)
+ local kernel_settings = TableDeepCopy(s.common_settings)
-kernel_settings.cc.includes:Add("src/common/include/kogata",
- "src/kernel/include")
+ kernel_settings.cc.includes:Add("src/common/include/kogata",
+ "src/kernel/include")
-kernel_settings.link.flags:Add("-T src/kernel/linker.ld")
+ kernel_settings.link.flags:Add("-T src/kernel/linker.ld")
-kernel_source = {
- Collect('src/kernel/core/*.s'),
- Collect('src/kernel/dev/*.s'),
- Collect('src/kernel/core/*.c'),
- Collect('src/kernel/dev/*.c'),
- Collect('src/kernel/fs/*.c'),
- Collect('src/kernel/user/*.c'),
-}
-kernel_obj = Compile(kernel_settings, kernel_source)
-
-kernel = Link(kernel_settings, "kernel", {kernel_obj, common_libc, common_libkogata})
+ kernel_source = {
+ Collect('src/kernel/core/*.s'),
+ Collect('src/kernel/dev/*.s'),
+ Collect('src/kernel/core/*.c'),
+ Collect('src/kernel/dev/*.c'),
+ Collect('src/kernel/fs/*.c'),
+ Collect('src/kernel/user/*.c'),
+ }
+ obj = Compile(kernel_settings, kernel_source)
+ return {
+ obj = obj,
+ bin = Link(kernel_settings, "kernel", {obj, common.libc, common.libkogata})
+ }
+end
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c
index dd66805..8ce9f0a 100644
--- a/src/kernel/core/kmain.c
+++ b/src/kernel/core/kmain.c
@@ -69,8 +69,12 @@ void kmain(multiboot_info_t *mbd, int32_t mb_magic) {
// to allocate memory ; they just increment it of the allocated quantity
void* kernel_data_end = (void*)&k_end_addr;
- elf_shdr_t *elf_sections = (elf_shdr_t*)(mbd->elf_sec.addr + K_HIGHHALF_ADDR);
- ASSERT(sizeof(elf_shdr_t) == mbd->elf_sec.size);
+
+ elf_shdr_t *elf_sections = 0;
+ if (mbd->elf_sec.size != 0) {
+ elf_sections = (elf_shdr_t*)(mbd->elf_sec.addr + K_HIGHHALF_ADDR);
+ ASSERT(mbd->elf_sec.size == 0 || sizeof(elf_shdr_t) == mbd->elf_sec.size);
+ }
dbglog_setup();
diff --git a/src/kernel/user/syscall.c b/src/kernel/user/syscall.c
index 9497bf2..e89f62d 100644
--- a/src/kernel/user/syscall.c
+++ b/src/kernel/user/syscall.c
@@ -325,6 +325,7 @@ uint32_t select_sc(sc_args_t args) {
if (h) {
fds[i].got_flags = file_poll(h, &wait_objs[n_wait_objs]);
if (wait_objs[n_wait_objs]) n_wait_objs++;
+ dbg_printf("KERNEL fds[%d].got_flags = 0x%p (fd %d)\n", i, fds[i].got_flags,fds[i].fd);
if (fds[i].got_flags & fds[i].req_flags) ret = true;
}
}
diff --git a/src/lib/bam.lua b/src/lib/bam.lua
index 44edad2..b7bee20 100644
--- a/src/lib/bam.lua
+++ b/src/lib/bam.lua
@@ -1,11 +1,15 @@
-local function lib(name)
- local source = {Collect('src/lib/' .. name .. '/*.c'),
- Collect('src/lib/' .. name .. '/*.s')}
- return Compile(user_settings, source)
-end
-
-libc = {lib('libc'), common_libc, common_libkogata}
+return function(s, common)
+ local function lib(name)
+ local source = {Collect('src/lib/' .. name .. '/*.c'),
+ Collect('src/lib/' .. name .. '/*.s')}
+ return Compile(s.user_settings, source)
+ end
+
+ local libc = {lib('libc'), common.libc, common.libkogata}
-libkogata = {lib('libkogata'), libc}
-
-liblua = {lib('lua'), libc}
+ return {
+ libc = libc,
+ libkogata = {lib('libkogata'), libc},
+ liblua = {lib('lua'), libc}
+ }
+end
diff --git a/src/lib/libc/syscall.c b/src/lib/libc/syscall.c
index 83708da..32aba00 100644
--- a/src/lib/libc/syscall.c
+++ b/src/lib/libc/syscall.c
@@ -9,7 +9,8 @@ static inline uint32_t sc_docall(uint32_t a, uint32_t b, uint32_t c, uint32_t d,
uint32_t ret;
asm volatile("int $0x40"
:"=a"(ret)
- :"a"(a),"b"(b),"c"(c),"d"(d),"S"(ss),"D"(dd));
+ :"a"(a),"b"(b),"c"(c),"d"(d),"S"(ss),"D"(dd)
+ :"memory");
return ret;
}
@@ -108,7 +109,7 @@ fd_t sc_use_token(token_t *tok) {
}
bool sc_make_fs(const char* name, const char* driver, fd_t source, const char* options) {
- volatile sc_make_fs_args_t args = {
+ sc_make_fs_args_t args = {
.driver = driver,
.driver_strlen = strlen(driver),
.fs_name = name,
@@ -124,7 +125,7 @@ bool sc_fs_add_source(const char* fs, fd_t source, const char* options) {
return sc_docall(SC_FS_ADD_SRC, (uint32_t)fs, strlen(fs), source, (uint32_t)options, strlen(options));
}
bool sc_fs_subfs(const char* name, const char* orig_fs, const char* root, int ok_modes) {
- volatile sc_subfs_args_t args = {
+ sc_subfs_args_t args = {
.new_name = name,
.new_name_strlen = strlen(name),
.from_fs = orig_fs,
diff --git a/src/sysbin/bam.lua b/src/sysbin/bam.lua
index 8628bf1..9e13a8a 100644
--- a/src/sysbin/bam.lua
+++ b/src/sysbin/bam.lua
@@ -1,23 +1,24 @@
-local function sysbin_settings(name)
- local s = TableDeepCopy(user_settings)
- s.link.flags:Add("-T src/lib/linker.ld",
- "-Xlinker -Map=build/sysbin/" .. name .. ".map")
- return s
-end
+return function(s, lib)
+ local function sysbin_settings(name)
+ local s = TableDeepCopy(s.user_settings)
+ s.link.flags:Add("-T src/lib/linker.ld")
+ return s
+ end
-local function sysbin_exe(name, deps)
- local s = sysbin_settings(name)
+ local function sysbin_exe(name, deps)
+ local s = sysbin_settings(name)
- local src = Collect('src/sysbin/' .. name .. '/*.c')
- local obj = Compile(s, src)
+ local src = Collect('src/sysbin/' .. name .. '/*.c')
+ local obj = Compile(s, src)
- return Link(s, 'sysbin/' .. name .. ".bin", {obj, deps})
-end
+ return Link(s, 'sysbin/' .. name .. ".bin", {obj, deps})
+ end
-sysbin = {
- sysbin_exe('init', {libkogata}),
- sysbin_exe('giosrv', {libkogata}),
- sysbin_exe('login', {libkogata}),
- sysbin_exe('terminal', {libkogata}),
- sysbin_exe('shell', {libkogata}),
-}
+ return {
+ sysbin_exe('init', {lib.libkogata}),
+ sysbin_exe('giosrv', {lib.libkogata}),
+ sysbin_exe('login', {lib.libkogata}),
+ sysbin_exe('terminal', {lib.libkogata}),
+ sysbin_exe('shell', {lib.libkogata}),
+ }
+end
diff --git a/src/tests/ktests/bam.lua b/src/tests/ktests/bam.lua
index b721a8b..c1be337 100644
--- a/src/tests/ktests/bam.lua
+++ b/src/tests/ktests/bam.lua
@@ -1,35 +1,38 @@
-local obj_nokmain = {}
-for name in TableWalk(kernel_obj) do
- if not name:find('kmain') then
- table.insert(obj_nokmain, name)
+return function(s, common, kernel_obj)
+ local tests = {}
+
+ local obj_nokmain = {}
+ for name in TableWalk(kernel_obj) do
+ if not name:find('kmain') then
+ table.insert(obj_nokmain, name)
+ end
end
-end
-for _, name in pairs({
- "breakpoint",
- "btree1", "btree2",
- "cmdline",
- "hashtbl1", "hashtbl2",
- "kmalloc",
- "region1"
-}) do
- local map = "build/tests/ktest_" .. name .. ".map"
+ for _, name in pairs({
+ "breakpoint",
+ "btree1", "btree2",
+ "cmdline",
+ "hashtbl1", "hashtbl2",
+ "kmalloc",
+ "region1"
+ }) do
+ local test_config = TableDeepCopy(s.common_settings)
+ test_config.cc.includes:Add("src/kernel/include",
+ "src/common/include/kogata",
+ "src/tests/ktests/"..name)
+ test_config.cc.flags:Add('-DBUILD_KERNEL_TEST')
+ test_config.link.flags:Add("-T src/kernel/linker.ld")
+ test_config.cc.extension = ".ktest_" .. name .. ".o"
- local test_config = TableDeepCopy(common_settings)
- test_config.cc.includes:Add("src/kernel/include",
- "src/tests/ktests/"..name)
- test_config.cc.flags:Add('-DBUILD_KERNEL_TEST')
- test_config.link.flags:Add("-T src/kernel/linker.ld",
- "-Xlinker -Map=" .. map)
- test_config.cc.extension = ".ktest_" .. name .. ".o"
+ local kmain = Compile(test_config, "src/kernel/core/kmain.c")
+ local bin = Link(test_config, "tests/ktest_"..name,
+ {obj_nokmain, kmain, common.libkogata, common.libc, common.libalgo})
- local kmain = Compile(test_config, "src/kernel/core/kmain.c")
- local bin = Link(test_config, "tests/ktest_"..name,
- {obj_nokmain, kmain, common_libkogata, common_libc, common_libalgo})
+ local out = bin .. ".log"
+ AddJob(out, "ktest " .. name, "./src/tests/ktests/run_qemu_test.sh " .. bin .. " " .. out)
+ AddDependency(out, bin)
+ table.insert(tests, out)
+ end
- local out = "build/tests/ktest_"..name..".log"
- AddJob(out, "ktest " .. name, "./src/tests/ktests/run_qemu_test.sh " .. bin .. " " .. out .. " " .. map)
- AddDependency(out, bin)
- table.insert(tests, out)
+ return tests
end
-
diff --git a/src/tests/ktests/run_qemu_test.sh b/src/tests/ktests/run_qemu_test.sh
index 4249a96..bc86f12 100755
--- a/src/tests/ktests/run_qemu_test.sh
+++ b/src/tests/ktests/run_qemu_test.sh
@@ -2,12 +2,11 @@
BINFILE=$1
LOGFILE=$2
-MAPFILE=$3
RESULTFILE=`mktemp`
PIDFILE=`mktemp`
-(timeout 3s qemu-system-i386 -kernel $BINFILE -initrd $MAPFILE -serial stdio -m 16 -display none 2>/dev/null \
+(timeout 3s qemu-system-i386 -kernel $BINFILE -serial stdio -m 16 -display none 2>/dev/null \
& echo $! >$PIDFILE) \
| tee >(grep -m 1 "TEST-" >$RESULTFILE; kill -INT `cat $PIDFILE`) > $LOGFILE
diff --git a/src/tests/slab_test/bam.lua b/src/tests/slab_test/bam.lua
index 87c6666..cd5ad2d 100644
--- a/src/tests/slab_test/bam.lua
+++ b/src/tests/slab_test/bam.lua
@@ -1,11 +1,14 @@
-local source = {"src/common/libkogata/slab_alloc.c",
- "src/tests/slab_test/slab_test.c"}
-local obj = Compile(host_settings, source)
+return function(s)
+ local source = {"src/common/libkogata/slab_alloc.c",
+ "src/tests/slab_test/slab_test.c"}
+ local obj = Compile(s.host_settings, source)
-local bin = Link(host_settings, "build/tests/slab_test", obj)
+ local f = s.host_settings.cc.Output(s.host_settings, "tests/slab_test")
+ local bin = Link(s.host_settings, f, obj)
-local slab_test = "build/tests/slab_test.log"
-AddJob(slab_test, "slab_test", "./" .. bin .. " > " .. slab_test)
-AddDependency(slab_test, bin)
+ local slab_test = f .. ".log"
+ AddJob(slab_test, "slab_test", "./" .. bin .. " > " .. slab_test)
+ AddDependency(slab_test, bin)
-table.insert(tests, slab_test)
+ return slab_test
+end
diff --git a/src/tests/slab_test/slab_test.c b/src/tests/slab_test/slab_test.c
index 747c785..31af03d 100644
--- a/src/tests/slab_test/slab_test.c
+++ b/src/tests/slab_test/slab_test.c
@@ -1,4 +1,4 @@
-#include <slab_alloc.h>
+#include <kogata/slab_alloc.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/tests/utests/bam.lua b/src/tests/utests/bam.lua
index 6137399..abbce88 100644
--- a/src/tests/utests/bam.lua
+++ b/src/tests/utests/bam.lua
@@ -1,21 +1,24 @@
-for _, name in pairs({
- "chan1", "chan2",
- "fs1", "fs2",
- "malloc",
- "subfs"
-}) do
- local map = "build/tests/utest_" .. name .. ".map"
+return function(s, kernel, lib)
+ local tests = {}
- local config = TableDeepCopy(user_settings)
- config.link.flags:Add( '-Xlinker -Map=' .. map,
- '-T src/sysbin/linker.ld')
+ for _, name in pairs({
+ "chan1", "chan2",
+ "fs1", "fs2",
+ "malloc",
+ "subfs"
+ }) do
+ local config = TableDeepCopy(s.user_settings)
+ config.link.flags:Add('-T src/lib/linker.ld')
- local obj = Compile(config, 'src/tests/utests/' .. name .. '/test.c')
- local bin = Link(config, 'tests/utest_' .. name, {obj, libkogata})
+ local obj = Compile(config, 'src/tests/utests/' .. name .. '/test.c')
+ local bin = Link(config, 'tests/utest_' .. name, {obj, lib.libkogata})
- local out = "build/tests/utest_"..name..".log"
- AddJob(out, "utest " .. name, "./src/tests/utests/run_qemu_test.sh " .. bin .. " " .. out .. " " .. map)
- AddDependency(out, bin)
- AddDependency(out, kernel)
- table.insert(tests, out)
+ local out = bin .. ".log"
+ AddJob(out, "utest " .. name, "./src/tests/utests/run_qemu_test.sh " .. bin .. " " .. out .. " " .. kernel)
+ AddDependency(out, bin)
+ AddDependency(out, kernel)
+ table.insert(tests, out)
+ end
+
+ return tests
end
diff --git a/src/tests/utests/chan1/test.c b/src/tests/utests/chan1/test.c
index 1b89255..0c4e61a 100644
--- a/src/tests/utests/chan1/test.c
+++ b/src/tests/utests/chan1/test.c
@@ -1,26 +1,26 @@
#include <string.h>
-#include <malloc.h>
+#include <kogata/malloc.h>
-#include <syscall.h>
-#include <debug.h>
+#include <kogata/syscall.h>
+#include <kogata/debug.h>
int main(int argc, char **argv) {
- fd_pair_t ch = make_channel(false);
+ fd_pair_t ch = sc_make_channel(false);
char* s = "Hello, world!";
- ASSERT(write(ch.a, 0, strlen(s), s) == strlen(s));
+ ASSERT(sc_write(ch.a, 0, strlen(s), s) == strlen(s));
char buf[128];
- ASSERT(read(ch.b, 0, 128, buf) == strlen(s));
+ ASSERT(sc_read(ch.b, 0, 128, buf) == strlen(s));
ASSERT(strncmp(s, buf, strlen(s)) == 0);
- close(ch.a);
+ sc_close(ch.a);
sel_fd_t sel = { .fd = ch.b, .req_flags = SEL_ERROR };
- ASSERT(select(&sel, 1, 0));
+ ASSERT(sc_select(&sel, 1, 0));
ASSERT(sel.got_flags & SEL_ERROR);
- close(ch.b);
+ sc_close(ch.b);
dbg_printf("(TEST-OK)\n");
diff --git a/src/tests/utests/chan2/test.c b/src/tests/utests/chan2/test.c
index a2f8b3f..c972e79 100644
--- a/src/tests/utests/chan2/test.c
+++ b/src/tests/utests/chan2/test.c
@@ -1,9 +1,9 @@
#include <string.h>
-#include <malloc.h>
+#include <kogata/malloc.h>
-#include <syscall.h>
-#include <debug.h>
+#include <kogata/syscall.h>
+#include <kogata/debug.h>
volatile int step = 0; // volatile because thread-shared
@@ -15,6 +15,8 @@ const char* msg_d = "hello world";
void listen_thread(fd_t c1, fd_t c2) {
dbg_printf("listen_thread started\n");
+ dbg_printf("Got args: %d, %d\n", c1, c2);
+
sel_fd_t sel[2];
sel[0].fd = c1;
sel[1].fd = c2;
@@ -23,49 +25,49 @@ void listen_thread(fd_t c1, fd_t c2) {
char buf[128];
dbg_printf("Doing first select...\n");
- ASSERT(select(sel, 2, -1));
+ ASSERT(sc_select(sel, 2, -1));
dbg_printf("%x %x\n", sel[0].got_flags, sel[1].got_flags);
ASSERT(sel[0].got_flags & SEL_READ);
ASSERT(!(sel[1].got_flags & SEL_READ));
- ASSERT(read(c1, 0, strlen(msg_a), buf) == strlen(msg_a));
+ ASSERT(sc_read(c1, 0, strlen(msg_a), buf) == strlen(msg_a));
ASSERT(strncmp(buf, msg_a, strlen(msg_a)) == 0);
- ASSERT(write(c1, 0, strlen(msg_c), msg_c) == strlen(msg_c));
+ ASSERT(sc_write(c1, 0, strlen(msg_c), msg_c) == strlen(msg_c));
step = 1;
dbg_printf("Doing second select...\n");
- ASSERT(select(sel, 2, -1));
+ ASSERT(sc_select(sel, 2, -1));
dbg_printf("%x %x\n", sel[0].got_flags, sel[1].got_flags);
ASSERT(sel[1].got_flags & SEL_READ);
ASSERT(!(sel[0].got_flags & SEL_READ));
- ASSERT(read(c2, 0, strlen(msg_b), buf) == strlen(msg_b));
+ ASSERT(sc_read(c2, 0, strlen(msg_b), buf) == strlen(msg_b));
ASSERT(strncmp(buf, msg_b, strlen(msg_b)) == 0);
- ASSERT(write(c2, 0, strlen(msg_d), msg_d) == strlen(msg_d));
+ ASSERT(sc_write(c2, 0, strlen(msg_d), msg_d) == strlen(msg_d));
step = 2;
dbg_printf("Doing third select...\n");
- ASSERT(select(sel, 2, -1));
+ ASSERT(sc_select(sel, 2, -1));
dbg_printf("%x %x\n", sel[0].got_flags, sel[1].got_flags);
ASSERT(sel[0].got_flags & SEL_ERROR);
ASSERT(!(sel[1].got_flags & SEL_ERROR));
- close(c1);
+ sc_close(c1);
step = 3;
dbg_printf("Doing fourth select...\n");
- ASSERT(select(sel + 1, 1, -1));
+ ASSERT(sc_select(sel + 1, 1, -1));
dbg_printf("%x\n", sel[1].got_flags);
ASSERT(sel[1].got_flags & SEL_ERROR);
- close(c2);
+ sc_close(c2);
step = 4;
- exit_thread();
+ sc_exit_thread();
}
int main(int argc, char **argv) {
- fd_pair_t ch1 = make_channel(false);
+ fd_pair_t ch1 = sc_make_channel(false);
ASSERT(ch1.a != 0 && ch1.b != 0);
- fd_pair_t ch2 = make_channel(false);
+ fd_pair_t ch2 = sc_make_channel(false);
ASSERT(ch2.a != 0 && ch2.b != 0);
void* stack = malloc(0x1000);
@@ -77,42 +79,42 @@ int main(int argc, char **argv) {
*(--esp) = ch2.a;
*(--esp) = ch1.a;
*(--esp) = 0; // false return address
- dbg_printf("launching waiter thread\n");
- ASSERT(sys_new_thread(listen_thread, esp));
+ dbg_printf("launching waiter thread (args: %d, %d)\n", ch1.a, ch2.a);
+ ASSERT(sc_sys_new_thread(listen_thread, esp));
fd_t c1 = ch1.b, c2 = ch2.b;
// -- the test on the first channel
- ASSERT(write(c1, 0, strlen(msg_a), msg_a) == strlen(msg_a));
+ ASSERT(sc_write(c1, 0, strlen(msg_a), msg_a) == strlen(msg_a));
dbg_printf("wait for step1 signal\n");
while(step != 1);
dbg_printf("got step1 signal, proceeding\n");
- ASSERT(read(c1, 0, strlen(msg_c), buf) == strlen(msg_c));
+ ASSERT(sc_read(c1, 0, strlen(msg_c), buf) == strlen(msg_c));
ASSERT(strncmp(msg_c, buf, strlen(msg_c)) == 0);
// -- the test on the second channel
- ASSERT(write(c2, 0, strlen(msg_b), msg_b) == strlen(msg_b));
+ ASSERT(sc_write(c2, 0, strlen(msg_b), msg_b) == strlen(msg_b));
dbg_printf("wait for step2 signal\n");
while(step != 2);
dbg_printf("got step2 signal, proceeding\n");
- ASSERT(read(c2, 0, strlen(msg_d), buf) == strlen(msg_d));
+ ASSERT(sc_read(c2, 0, strlen(msg_d), buf) == strlen(msg_d));
ASSERT(strncmp(msg_d, buf, strlen(msg_d)) == 0);
// -- closing stuff
- close(c1);
+ sc_close(c1);
dbg_printf("waiting for step3 signal\n");
while(step != 3);
dbg_printf("got step3 signal, proceeding\n");
- close(c2);
+ sc_close(c2);
dbg_printf("waiting for step4 signal\n");
while(step != 4);
diff --git a/src/tests/utests/fs1/test.c b/src/tests/utests/fs1/test.c
index 79db13b..7356c14 100644
--- a/src/tests/utests/fs1/test.c
+++ b/src/tests/utests/fs1/test.c
@@ -1,37 +1,37 @@
#include <string.h>
-#include <malloc.h>
+#include <kogata/malloc.h>
-#include <syscall.h>
-#include <debug.h>
+#include <kogata/syscall.h>
+#include <kogata/debug.h>
int main(int argc, char **argv) {
dbg_print("Hello, world! from user process.\n");
- fd_t f = open("io:/", FM_READDIR);
+ fd_t f = sc_open("io:/", FM_READDIR);
dbg_printf("openned /: %d\n", f);
ASSERT(f != 0);
dirent_t x;
size_t ent_no = 0;
- while (readdir(f, ent_no++, &x)) {
+ while (sc_readdir(f, ent_no++, &x)) {
dbg_printf("- '%s' %p %d\n", x.name, x.st.type, x.st.size);
if (x.st.type == FT_REGULAR) {
char buf[256];
strcpy(buf, "io:/");
strcpy(buf+4, x.name);
dbg_printf("trying to open %s...\n", buf);
- fd_t ff = open(buf, FM_READ);
+ fd_t ff = sc_open(buf, FM_READ);
ASSERT(ff != 0);
dbg_printf("ok, open as %d\n", ff);
char* cont = malloc(x.st.size + 1);
- ASSERT(read(ff, 0, x.st.size, cont) == x.st.size);
+ ASSERT(sc_read(ff, 0, x.st.size, cont) == x.st.size);
cont[x.st.size] = 0;
dbg_printf("> '%s'\n", cont);
- close(ff);
+ sc_close(ff);
}
}
- close(f);
+ sc_close(f);
dbg_printf("(TEST-OK)\n");
diff --git a/src/tests/utests/fs2/test.c b/src/tests/utests/fs2/test.c
index 0acf11d..1b72eb7 100644
--- a/src/tests/utests/fs2/test.c
+++ b/src/tests/utests/fs2/test.c
@@ -1,28 +1,28 @@
#include <string.h>
-#include <malloc.h>
+#include <kogata/malloc.h>
-#include <syscall.h>
-#include <debug.h>
+#include <kogata/syscall.h>
+#include <kogata/debug.h>
int main(int argc, char **argv) {
dbg_print("Hello, world! from user process.\n");
- fd_t f = open("io:/mod", FM_READDIR);
+ fd_t f = sc_open("io:/mod", FM_READDIR);
dbg_printf("openned io:/mod as %d\n", f);
ASSERT(f != 0);
dirent_t x;
size_t ent_no = 0;
- while (ent_no < 2) {
- ASSERT (readdir(f, ent_no++, &x));
+ while (ent_no < 1) {
+ ASSERT (sc_readdir(f, ent_no++, &x));
ASSERT((!strcmp(x.name, "utest_fs2.bin")) || (!strcmp(x.name, "kernel.map")));
ASSERT(x.st.type == FT_REGULAR);
}
- ASSERT(!readdir(f, ent_no++, &x));
- close(f);
+ ASSERT(!sc_readdir(f, ent_no++, &x));
+ sc_close(f);
dbg_printf("(TEST-OK)\n");
diff --git a/src/tests/utests/malloc/test.c b/src/tests/utests/malloc/test.c
index fb2f3b9..9a937aa 100644
--- a/src/tests/utests/malloc/test.c
+++ b/src/tests/utests/malloc/test.c
@@ -1,10 +1,10 @@
#include <string.h>
-#include <malloc.h>
+#include <kogata/malloc.h>
-#include <syscall.h>
-#include <debug.h>
-#include <region_alloc.h>
+#include <kogata/syscall.h>
+#include <kogata/debug.h>
+#include <kogata/region_alloc.h>
int main(int argc, char **argv) {
dbg_print("(BEGIN-USER-TEST malloc-test)\n");
diff --git a/src/tests/utests/run_qemu_test.sh b/src/tests/utests/run_qemu_test.sh
index e806501..b9f3c36 100755
--- a/src/tests/utests/run_qemu_test.sh
+++ b/src/tests/utests/run_qemu_test.sh
@@ -2,12 +2,13 @@
BINFILE=$1
LOGFILE=$2
+KERNEL=$3
RESULTFILE=`mktemp`
PIDFILE=`mktemp`
-(timeout 3s qemu-system-i386 -kernel build/kernel.bin -append "init=io:/mod/`basename $BINFILE`" \
- -initrd "$BINFILE,build/kernel.map" -serial stdio -m 16 -display none 2>/dev/null \
+(timeout 3s qemu-system-i386 -kernel $KERNEL -append "init=io:/mod/`basename $BINFILE`" \
+ -initrd "$BINFILE" -serial stdio -m 16 -display none 2>/dev/null \
& echo $! >$PIDFILE) \
| tee >(grep -m 1 "TEST-" >$RESULTFILE; kill -INT `cat $PIDFILE`) >$LOGFILE
diff --git a/src/tests/utests/subfs/test.c b/src/tests/utests/subfs/test.c
index 52c1025..b237181 100644
--- a/src/tests/utests/subfs/test.c
+++ b/src/tests/utests/subfs/test.c
@@ -1,30 +1,30 @@
#include <string.h>
-#include <malloc.h>
+#include <kogata/malloc.h>
-#include <syscall.h>
-#include <debug.h>
+#include <kogata/syscall.h>
+#include <kogata/debug.h>
int main(int argc, char **argv) {
dbg_print("Hello, world! from user process.\n");
- ASSERT(fs_subfs("mod", "io", "/mod", FM_READ | FM_READDIR));
+ ASSERT(sc_fs_subfs("mod", "io", "/mod", FM_READ | FM_READDIR));
- fd_t f = open("mod:/", FM_READDIR);
+ fd_t f = sc_open("mod:/", FM_READDIR);
dbg_printf("openned mod:/ as %d\n", f);
ASSERT(f != 0);
dirent_t x;
size_t ent_no = 0;
- while (ent_no < 2) {
- ASSERT (readdir(f, ent_no++, &x));
+ while (ent_no < 1) {
+ ASSERT (sc_readdir(f, ent_no++, &x));
ASSERT((!strcmp(x.name, "utest_subfs.bin")) || (!strcmp(x.name, "kernel.map")));
ASSERT(x.st.type == FT_REGULAR);
}
- ASSERT(!readdir(f, ent_no++, &x));
- close(f);
+ ASSERT(!sc_readdir(f, ent_no++, &x));
+ sc_close(f);
dbg_printf("(TEST-OK)\n");