Skip to content

Commit

Permalink
Merge pull request #24 from chaos4ever/feature/added-unit-test-infras…
Browse files Browse the repository at this point in the history
…tructure

Added unit test infrastructure
  • Loading branch information
perlun committed May 2, 2015
2 parents dbc060c + f1a6c00 commit d6f372c
Show file tree
Hide file tree
Showing 26 changed files with 518 additions and 218 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.vagrant
floppy.img

*.dep
*.o
*.a
floppy.img

storm/current-arch
storm/ia32/storm
storm/include/storm/current-arch
.vagrant
storm_tests/ia32/ia32_tests

servers/system/boot/boot
servers/system/console/console
Expand Down
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
env: CC=gcc
before_script:
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get update
- sudo apt-get install g++-4.7 nasm
- sudo apt-get install gcc-multilib nasm
- ./install_cmocka.sh
script:
- rake
- rake tests
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ task :storm do |folder|
sh "cd #{folder} && #{RAKE_COMMAND}"
end

desc "Compiles the unit tests for the 'storm' kernel."
task :build_storm_tests => :storm do
sh "cd storm_tests && #{RAKE_COMMAND}"
end

desc 'Runs the unit tests'
task :tests => [:build_storm_tests] do
sh "cd storm_tests && #{RAKE_COMMAND} tests"
end

task :libraries => [ :storm ] do |folder|
sh "cd #{folder} && #{RAKE_COMMAND}"
end
Expand Down
30 changes: 21 additions & 9 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
Vagrant.configure(2) do |config|
config.vm.box = 'chef/debian-7.8'
config.vm.provision 'shell', inline: <<-SHELL
set -e
sudo apt-get update
sudo apt-get install -y git mtools nasm rake astyle qemu
echo 'cd /vagrant' >> /home/vagrant/.bashrc
cd /vagrant && bzip2 -dc misc/grub.img.bz2 > floppy.img
echo 'drive a: file="/vagrant/floppy.img" 1.44m mformat_only' > /etc/mtools.conf
echo '-U' > /home/vagrant/.astylerc
echo '-H' >> /home/vagrant/.astylerc
echo '-S' >> /home/vagrant/.astylerc
set -e
sudo apt-get update
sudo apt-get install -y \
astyle \
cmake \
gcc-multilib \
git \
mtools \
nasm \
qemu \
rake
cd /vagrant
./install_cmocka.sh
cd /vagrant && bzip2 -dc misc/grub.img.bz2 > floppy.img
echo 'drive a: file="/vagrant/floppy.img" 1.44m mformat_only' > /etc/mtools.conf
echo 'cd /vagrant' >> /home/vagrant/.bashrc
echo '-U' > /home/vagrant/.astylerc
echo '-H' >> /home/vagrant/.astylerc
echo '-S' >> /home/vagrant/.astylerc
SHELL
end
14 changes: 14 additions & 0 deletions install_cmocka.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

cd /tmp
rm -rf cmocka*
wget https://cmocka.org/files/1.0/cmocka-1.0.1.tar.xz
tar xf cmocka-1.0.1.tar.xz
cd cmocka-1.0.1
mkdir build
cd build
cmake -DCMAKE_C_FLAGS=-m32 ..
make
sudo make install
sudo sh -c 'echo /usr/local/lib >> /etc/ld.so.conf'
sudo /sbin/ldconfig
7 changes: 6 additions & 1 deletion rakelib/common_rules.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rule '.o' => [ '.c' ] do |t|
begin
print((t.source + ' ').cyan)
command = "#{CC} -o #{t.name} #{CFLAGS} #{INCLUDES.join(' ')} -c #{t.source}"
command = "#{CC} -o #{t.name} #{cflags} #{INCLUDES.join(' ')} -c #{t.source}"
sh command
rescue
puts "Error compiling #{t.source}. Full command line was: #{command}"
Expand Down Expand Up @@ -41,3 +41,8 @@ rule '.o' => [ '.asm' ] do |t|
raise
end
end

def cflags
flags = CFLAGS.join(' ') if CFLAGS.respond_to?(:join)
flags ||= CFLAGS
end
3 changes: 0 additions & 3 deletions rakelib/common_settings.rake
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
verbose false

# FIXME: Should consider supporting a toplevel Rakefile.local or something where you can define this, so you don't have to
# modify a version-controlled file.

UNAME = `uname`.strip

case UNAME
Expand Down
2 changes: 1 addition & 1 deletion servers/servers.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Common settings and Rake rules for all libraries.
# Common settings and Rake rules for all servers.

Rake.application.options.rakelib = ["#{File.dirname(__FILE__)}/../rakelib"] if Rake.application.options.rakelib.first == 'rakelib'

Expand Down
2 changes: 1 addition & 1 deletion storm/generic/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OBJECTS = %w(
# TODO: Would like to use STORM_GENERIC_LIB, but for whatever reason it is not available in this context.
OUTPUT = 'libstorm_generic.a'

task :default => [ :banner, OUTPUT ] do
task :default => [:banner, OUTPUT] do
puts
end

Expand Down
25 changes: 13 additions & 12 deletions storm/ia32/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,8 @@ u32 multiboot_header[] __attribute__ ((section(".init.pre"), unused)) =

// FIXME: Put those in another file. We should have a better system for local include files...
void _start (void) INIT_CODE;
extern int main (int arguments, char *argument[]);

// This is the kernel. :)
static void INIT_CODE kernel_entry (void) NORETURN;
static void INIT_CODE kernel_entry(void)
{
multiboot_init();

main(((u8 *) arguments_kernel)[0], (char **) &arguments_kernel[4]);

// This code should never really get called.
idle();
}
extern int kernel_main (int arguments, char *argument[]);

// This is the kernel entry point.
// FIXME: Use memory_copy and memory_set instead of inline assembler. The current way is very hard to optomize for e.g.
Expand Down Expand Up @@ -164,3 +153,15 @@ void _start(void)
: "n" (SELECTOR_KERNEL_CODE),
"p" (&kernel_entry));
}

// When this gets called, the new (temporary) GDT has been set up and the segment selectors have been initialized with
// their new values.
static void INIT_CODE kernel_entry(void)
{
multiboot_init();

kernel_main(((u8 *) arguments_kernel)[0], (char **) &arguments_kernel[4]);

// This code should never really get called.
idle();
}
4 changes: 2 additions & 2 deletions storm/ia32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ static void INIT_CODE parse_kernel_arguments(unsigned int arguments, char *argum
}

// This is where the fun begins. Oh, yeah, we're going to Disneyland... blah blah. Terminator 2 RULEZ!
return_type main(int arguments, char *argument[]) INIT_CODE;
return_type kernel_main(int arguments, char *argument[]) INIT_CODE;

return_type main(int arguments, char *argument[])
return_type kernel_main(int arguments, char *argument[])
{
int servers_started = 0;

Expand Down
Loading

0 comments on commit d6f372c

Please sign in to comment.