diff options
author | Francesco Gazzetta <fgaz@fgaz.me> | 2021-06-21 15:53:14 +0200 |
---|---|---|
committer | Francesco Gazzetta <fgaz@fgaz.me> | 2021-06-21 15:53:14 +0200 |
commit | 72419d8ee07c80a17f077c2714f859ef06b4e459 (patch) | |
tree | f6ae558a953c8bacd7350bc03ed0d07f1f70846b /pkgs/development/compilers/qbe | |
parent | 4b8b7840cfcc3479d143cc8dbe0bf1499bf9919e (diff) |
qbe: add hello world test
Diffstat (limited to 'pkgs/development/compilers/qbe')
-rw-r--r-- | pkgs/development/compilers/qbe/default.nix | 6 | ||||
-rw-r--r-- | pkgs/development/compilers/qbe/test-can-run-hello-world.nix | 32 |
2 files changed, 37 insertions, 1 deletions
diff --git a/pkgs/development/compilers/qbe/default.nix b/pkgs/development/compilers/qbe/default.nix index 39241f5ee5354..35367b3b2efef 100644 --- a/pkgs/development/compilers/qbe/default.nix +++ b/pkgs/development/compilers/qbe/default.nix @@ -1,6 +1,7 @@ { lib, stdenv , fetchgit , unstableGitUpdater +, callPackage }: stdenv.mkDerivation rec { @@ -15,7 +16,10 @@ stdenv.mkDerivation rec { makeFlags = [ "PREFIX=$(out)" ]; - passthru.updateScript = unstableGitUpdater { }; + passthru = { + tests.can-run-hello-world = callPackage ./test-can-run-hello-world.nix {}; + updateScript = unstableGitUpdater { }; + }; meta = with lib; { homepage = "https://c9x.me/compile/"; diff --git a/pkgs/development/compilers/qbe/test-can-run-hello-world.nix b/pkgs/development/compilers/qbe/test-can-run-hello-world.nix new file mode 100644 index 0000000000000..5192bb881f343 --- /dev/null +++ b/pkgs/development/compilers/qbe/test-can-run-hello-world.nix @@ -0,0 +1,32 @@ +{ stdenv +, writeText +, qbe +}: + +# The hello world program available at https://c9x.me/compile/ +let helloWorld = writeText "hello-world.ssa" '' + function w $add(w %a, w %b) { # Define a function add + @start + %c =w add %a, %b # Adds the 2 arguments + ret %c # Return the result + } + export function w $main() { # Main function + @start + %r =w call $add(w 1, w 1) # Call add(1, 1) + call $printf(l $fmt, w %r, ...) # Show the result + ret 0 + } + data $fmt = { b "One and one make %d!\n", b 0 } +''; + +in stdenv.mkDerivation { + name = "qbe-test-can-run-hello-world"; + meta.timeout = 10; + buildCommand = '' + ${qbe}/bin/qbe -o asm.s ${helloWorld} + cc -o out asm.s + ./out | grep 'One and one make 2!' + touch $out + ''; +} + |