Skip to content

Commit

Permalink
add strcmp test
Browse files Browse the repository at this point in the history
  • Loading branch information
edadma committed Apr 2, 2018
1 parent cffaf3d commit d1a9b21
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 4 deletions.
30 changes: 27 additions & 3 deletions examples/strcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,28 @@ out( char c ) {

void
print( char* s ) {
for (char* p = s; *p;)
out( *p++ );
while (*s)
out( *s++ );

out( '\n' );
}

int
signum( int n ) {
return n == 0 ? 0 : n < 0 ? -1 : 1;
}

void
prints( int n ) {
static char* signs[] = {
"negative",
"zero",
"positive"
};

print( signs[signum(n) + 1] );
}

int
strcmp( char *s1, char *s2 ) {
unsigned char c1, c2;
Expand All @@ -30,5 +46,13 @@ void
main() {
char buf[34];

if (strcmp("abc", "abc") == 0)
prints( strcmp("", "") );
prints( strcmp("a", "a") );
prints( strcmp("", "abc") );
prints( strcmp("abc", "") );
prints( strcmp("abc", "abc") );
prints( strcmp("abc", "ab") );
prints( strcmp("ab", "abc") );
prints( strcmp("bc", "abc") );
prints( strcmp("abc", "bc") );
}
76 changes: 75 additions & 1 deletion src/test/scala/ExamplesNoCompressed.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@
package xyz.hyperreal.riscv

import org.scalatest._
Expand Down Expand Up @@ -130,5 +131,78 @@ class ExamplesNoCompressed extends FreeSpec with PropertyChecks with Matchers {
|positive
""".trim.stripMargin
}


"strcmp" in {
Run(
"""
|
|Hex dump of section '.text':
| 0x000100c0 37010100 ef004021 73500000 73500000 7.....@!sP..sP..
| 0x000100d0 00000000 00000000 00000000 00000000 ................
| 0x000100e0 00000000 00000000 00000000 00000000 ................
| 0x000100f0 00000000 00000000 00000000 00000000 ................
| 0x00010100 130101fe 233c8100 13040102 93070500 ....#<..........
| 0x00010110 a307f4fe b7070200 0347f4fe 2380e700 .........G..#...
| 0x00010120 13000000 03348101 13010102 67800000 .....4......g...
| 0x00010130 130101fe 233c1100 23388100 13040102 ....#<..#8......
| 0x00010140 2334a4fe 6f00c001 833784fe 13871700 #4..o....7......
| 0x00010150 2334e4fe 83c70700 13850700 eff05ffa #4............_.
| 0x00010160 833784fe 83c70700 e39007fe 1305a000 .7..............
| 0x00010170 eff01ff9 13000000 83308101 03340101 .........0...4..
| 0x00010180 13010102 67800000 130101fe 233c8100 ....g.......#<..
| 0x00010190 13040102 93070500 2326f4fe 8327c4fe ........#&...'..
| 0x000101a0 9b870700 63800702 8327c4fe 9b870700 ....c....'......
| 0x000101b0 63d60700 9307f0ff 6f000001 93071000 c.......o.......
| 0x000101c0 6f008000 93070000 13850700 03348101 o............4..
| 0x000101d0 13010102 67800000 130101fe 233c1100 ....g.......#<..
| 0x000101e0 23388100 13040102 93070500 2326f4fe #8..........#&..
| 0x000101f0 8327c4fe 13850700 eff01ff9 93070500 .'..............
| 0x00010200 9b871700 1b870700 b7170100 13173700 ..............7.
| 0x00010210 93870737 b307f700 83b70700 13850700 ...7............
| 0x00010220 eff01ff1 13000000 83308101 03340101 .........0...4..
| 0x00010230 13010102 67800000 130101fd 23348102 ....g.......#4..
| 0x00010240 13040103 233ca4fc 2338b4fc 833784fd ....#<..#8...7..
| 0x00010250 13871700 233ce4fc 83c70700 a307f4fe ....#<..........
| 0x00010260 833704fd 13871700 2338e4fc 83c70700 .7......#8......
| 0x00010270 2307f4fe 8347f4fe 93f7f70f 63900702 #....G......c...
| 0x00010280 8347f4fe 1b870700 8347e4fe 9b870700 .G.......G......
| 0x00010290 bb07f740 9b870700 6f000003 0347f4fe ...@....o....G..
| 0x000102a0 8347e4fe 1377f70f 93f7f70f e300f7fa .G...w..........
| 0x000102b0 8347f4fe 1b870700 8347e4fe 9b870700 .G.......G......
| 0x000102c0 bb07f740 9b870700 13850700 03348102 ...@.........4..
| 0x000102d0 13010103 67800000 130101fc 233c1102 ....g.......#<..
| 0x000102e0 23388102 13040104 13050000 eff0dfee #8..............
| 0x000102f0 13050000 eff05fee 1305f0ff eff0dfed ......_.........
| 0x00010300 13051000 eff05fed 13050000 eff0dfec ......_.........
| 0x00010310 13051000 eff05fec 1305f0ff eff0dfeb ......_.........
| 0x00010320 13051000 eff05feb 1305f0ff eff0dfea ......_.........
| 0x00010330 13000000 83308103 03340103 13010104 .....0...4......
| 0x00010340 67800000 g...
|
|
|Hex dump of section '.rodata':
| 0x00010348 6e656761 74697665 00000000 00000000 negative........
| 0x00010358 7a65726f 00000000 706f7369 74697665 zero....positive
| 0x00010368 00 .
|
|
|Hex dump of section '.data':
| 0x00011370 48030100 00000000 58030100 00000000 H.......X.......
| 0x00011380 60030100 00000000 `.......
|
|
""".trim.stripMargin
) shouldBe
"""
|zero
|zero
|negative
|positive
|zero
|positive
|negative
|positive
|negative
""".trim.stripMargin
}
}

0 comments on commit d1a9b21

Please sign in to comment.