OpenCores
URL https://opencores.org/ocsvn/tcp_socket/tcp_socket/trunk

Subversion Repositories tcp_socket

[/] [tcp_socket/] [trunk/] [chips2/] [test_suite/] [test_c2verilog] - Diff between revs 2 and 4

Show entire file | Details | Blame | View Log

Rev 2 Rev 4
Line 55... Line 55...
    print test, "...fail"
    print test, "...fail"
    sys.exit(0)
    sys.exit(0)
  else:
  else:
    print test, "...pass"
    print test, "...pass"
 
 
 
test("float file 1",
 
"""
 
void main(){
 
    file_write(1.0, "test_file");
 
    file_write(-1.0, "test_file");
 
    file_write(2.0, "test_file");
 
    file_write(-2.0, "test_file");
 
}
 
"""
 
)
 
 
 
test("float file 2",
 
"""
 
void main(){
 
    assert(file_read("test_file") == 1.0);
 
    assert(file_read("test_file") == -1.0);
 
    assert(file_read("test_file") == 2.0);
 
    assert(file_read("test_file") == -2.0);
 
}
 
"""
 
)
 
 
 
test_fails("array size1",
 
"""
 
int size(){
 
    return 10;
 
}
 
void main(){
 
    int blah[size()];
 
}
 
"""
 
)
 
 
 
test("array size2",
 
"""
 
void main(){
 
    const int b = 10;
 
    int a[b];
 
}
 
"""
 
)
 
 
 
test_fails("const 1",
 
"""
 
void main(){
 
    const int blah = 10;
 
    blah = 12;
 
}
 
"""
 
)
 
 
 
test("const 2",
 
"""
 
void main(){
 
    const int blah = 10;
 
    assert(blah == 10);
 
}
 
"""
 
)
 
 
 
test_fails("const 3",
 
"""
 
void main(){
 
    const float blah = 10;
 
    blah = 12;
 
}
 
"""
 
)
 
 
 
test("const 4",
 
"""
 
void main(){
 
    const float blah = 10;
 
    assert(blah == 10.0);
 
}
 
"""
 
)
 
 
 
test_fails("scope 1",
 
"""
 
void test(){
 
    int test_var = 1;
 
}
 
 
 
void main(){
 
    int blah = test_var;
 
}
 
"""
 
)
 
 
 
test("inplace float 1",
 
"""
 
void main(){
 
    float test = 1.0;
 
    test *= 2.0;
 
    assert(test == 2.0);
 
    test *= 2.0;
 
    assert(test == 4.0);
 
    test *= 2.0;
 
    assert(test == 8.0);
 
}
 
"""
 
)
 
 
 
test("inplace float 2",
 
"""
 
void main(){
 
    float test = 1.0;
 
    test += 2.0;
 
    assert(test == 3.0);
 
    test += 2.0;
 
    assert(test == 5.0);
 
    test += 2.0;
 
    assert(test == 7.0);
 
}
 
"""
 
)
 
 
 
test("inplace float 3",
 
"""
 
void main(){
 
    float test = 1.0;
 
    test -= 2.0;
 
    assert(test == -1.0);
 
    test -= 2.0;
 
    assert(test == -3.0);
 
    test -= 2.0;
 
    assert(test == -5.0);
 
}
 
"""
 
)
 
 
 
test("inplace float 4",
 
"""
 
void main(){
 
    float test = 1.0;
 
    test /= 2.0;
 
    assert(test == 0.5);
 
    test /= 2.0;
 
    assert(test == 0.25);
 
    test /= 2.0;
 
    assert(test == 0.125);
 
}
 
"""
 
)
 
 
 
test("inplace float 5",
 
"""
 
void main(){
 
    float test = 1.0;
 
    test *= 2;
 
    assert(test == 2.0);
 
    test *= 2;
 
    assert(test == 4.0);
 
    test *= 2;
 
    assert(test == 8.0);
 
}
 
"""
 
)
 
 
 
test("inplace float 6",
 
"""
 
void main(){
 
    float test = 1.0;
 
    test += 2;
 
    assert(test == 3.0);
 
    test += 2;
 
    assert(test == 5.0);
 
    test += 2;
 
    assert(test == 7.0);
 
}
 
"""
 
)
 
 
 
test("inplace float 7",
 
"""
 
void main(){
 
    float test = 1.0;
 
    test -= 2;
 
    assert(test == -1.0);
 
    test -= 2;
 
    assert(test == -3.0);
 
    test -= 2;
 
    assert(test == -5.0);
 
}
 
"""
 
)
 
 
 
test("inplace float 8",
 
"""
 
void main(){
 
    float test = 1.0;
 
    test /= 2;
 
    assert(test == 0.5);
 
    test /= 2;
 
    assert(test == 0.25);
 
    test /= 2;
 
    assert(test == 0.125);
 
}
 
"""
 
)
 
 
 
test("float 1",
 
"""
 
void main(){
 
    float test = 0.0;
 
    assert(test == 0.0);
 
}
 
"""
 
)
 
test("float 2",
 
"""
 
void main(){
 
    float test = 1.0;
 
    assert(test > 0.0);
 
}
 
"""
 
)
 
test("float 3",
 
"""
 
void main(){
 
    float test = 0.0;
 
    assert(test < 1.0);
 
}
 
"""
 
)
 
test("float 4",
 
"""
 
void main(){
 
    float test = 0.0;
 
    float a = -1.0;
 
    float b = -2.0;
 
    float c = 2.0;
 
    float d = 2.0;
 
    assert(test > -1.0);
 
    assert(a > b);
 
    assert(b < a);
 
    assert(c >= d);
 
    assert(c <= d);
 
}
 
"""
 
)
 
test("float 5",
 
"""
 
void main(){
 
    float test = 0.0;
 
    assert(test == 0.0);
 
}
 
"""
 
)
 
test("float 6",
 
"""
 
void main(){
 
    float blah[10];
 
    blah[0] = 0.0;
 
    blah[1] = 1.0;
 
    blah[2] = 2.0;
 
    blah[3] = 3.0;
 
    assert(blah[0] == 0.0);
 
    assert(blah[1] == 1.0);
 
    assert(blah[2] == 2.0);
 
    assert(blah[3] == 3.0);
 
}
 
"""
 
)
 
 
 
test("float 7",
 
"""
 
void main(){
 
    float a = 2.0;
 
    assert(a == 1.0 + 1.0);
 
}
 
"""
 
)
 
 
 
test("float 8",
 
"""
 
void main(){
 
    float a = 2.0;
 
    float b = 2.0;
 
    assert(a+b == 4.0);
 
}
 
"""
 
)
 
 
 
test("float 9",
 
"""
 
void main(){
 
    float a = -2.0;
 
    float b = -2.0;
 
    assert(a+b == -4.0);
 
}
 
"""
 
)
 
 
 
test("float 10",
 
"""
 
void main(){
 
    float a = 2.0;
 
    float b = 2.0;
 
    assert(a-b == -0.0);
 
}
 
"""
 
)
 
 
 
test("float 11",
 
"""
 
void main(){
 
    float a = 2.0;
 
    float b = 4.0;
 
    assert(a-b == -2.0);
 
}
 
"""
 
)
 
 
 
test("float 12",
 
"""
 
void main(){
 
    float a = 1.0;
 
    float b = 1.0;
 
    assert(a*b == 1.0);
 
}
 
"""
 
)
 
 
 
test("float 13",
 
"""
 
void main(){
 
    float a = 1.0;
 
    float b = -1.0;
 
    assert(a*b == -1.0);
 
}
 
"""
 
)
 
 
 
test("float 14",
 
"""
 
void main(){
 
    float a = -1.0;
 
    float b = -1.0;
 
    assert(a*b == 1.0);
 
}
 
"""
 
)
 
 
 
test("float 15",
 
"""
 
void main(){
 
    float a = -7.0;
 
    float b = 6.0;
 
    assert(a*b == -42.0);
 
}
 
"""
 
)
 
 
 
test("float 16",
 
"""
 
void main(){
 
    float a = 6.0;
 
    float b = 6.0;
 
    assert(a/b == 1.0);
 
}
 
"""
 
)
 
 
 
test("float 17",
 
"""
 
void main(){
 
    float a = 12.0;
 
    float b = 6.0;
 
    assert(a/b == 2.0);
 
}
 
"""
 
)
 
 
 
test("float 18",
 
"""
 
void main(){
 
    int a = 2;
 
    float b = 2.0;
 
    assert(a+b == 4.0);
 
}
 
"""
 
)
 
 
 
test("float 19",
 
"""
 
void main(){
 
    int a;
 
    float b = 2.0;
 
    a = b + 1.0;
 
    assert(a == 3);
 
}
 
"""
 
)
 
 
 
test("float 20",
 
"""
 
void main(){
 
    int a = 2;
 
    float b;
 
    b = a + 1.0;
 
    assert(b == 3.0);
 
}
 
"""
 
)
 
 
 
test("float 21",
 
"""
 
typedef struct {float a; float b;} mystruct;
 
void main(){
 
    mystruct a;
 
    a.a = 2.0;
 
    a.b = 3.0;
 
    assert(a.a == 2.0);
 
    assert(a.b == 3.0);
 
    assert(a.a + a.b == 5.0);
 
}
 
"""
 
)
 
test("float 22",
 
"""
 
typedef struct {float a; float b;} mystruct;
 
 
 
void test(mystruct a){
 
    assert(a.a == 2.0);
 
    assert(a.b == 3.0);
 
    assert(a.a + a.b == 5.0);
 
}
 
 
 
void main(){
 
    mystruct a;
 
    a.a = 2.0;
 
    a.b = 3.0;
 
    test(a);
 
}
 
"""
 
)
 
 
 
test("float 23",
 
"""
 
void test(float b){
 
    assert(b/6.0 == 2.0);
 
}
 
 
 
void main(){
 
    int a = 12.0;
 
    test(a);
 
}
 
"""
 
)
 
 
 
test("float 24",
 
"""
 
float test(){
 
    return 6.0;
 
}
 
 
 
void main(){
 
    int a = 12.0;
 
    assert(a/test() == 2.0);
 
}
 
"""
 
)
 
 
 
test("float 25",
 
"""
 
int main(){
 
  float a = 1.0;
 
  float b = 2.0;
 
  float c = 3.0;
 
  assert(a + b + c == 6.0);
 
  return 0;
 
}
 
 
 
""")
 
 
 
test("float 26",
 
"""
 
int main(){
 
  float a = 1.0;
 
  float b = 2.0;
 
  float c = 3.0;
 
  assert(a - b - c == -4.0);
 
  return 0;
 
}
 
 
 
""")
 
 
 
test("float 27",
 
"""
 
int main(){
 
  float a = 1.0;
 
  float b = 2.0;
 
  float c = 3.0;
 
  assert(a - (b - c) == 2.0);
 
  return 0;
 
}
 
 
 
""")
 
 
 
test("float 28",
 
"""
 
int main(){
 
  float a = 1.0;
 
  float b = 2.0;
 
  float c = 3.0;
 
  assert(a * b * c == 6.0);
 
  return 0;
 
}
 
 
 
""")
 
 
 
test("float 29",
 
"""
 
int main(){
 
  float a = 1.0;
 
  float b = 2.0;
 
  float c = 4.0;
 
  assert(a/b/c == 0.125);
 
  return 0;
 
}
 
 
 
""")
 
 
 
test("float 30",
 
"""
 
int main(){
 
  float a = 1.0;
 
  float b = 2.0;
 
  assert(a - - b == 3.0);
 
  return 0;
 
}
 
 
 
""")
 
 
 
test("struct_size 1",
 
"""
 
 
 
typedef struct {int a; int b;} mystruct;
 
 
 
void main(){
 
    assert(sizeof mystruct == 4);
 
}
 
"""
 
)
 
 
 
test("struct_size 2",
 
"""
 
 
 
typedef struct {long int a; int b;} mystruct;
 
 
 
void main(){
 
    assert(sizeof mystruct == 6);
 
}
 
"""
 
)
 
 
 
test("struct_size 3",
 
"""
 
 
 
typedef struct {long int a; int b;} struct_1;
 
typedef struct {long int a; struct_1 b;} mystruct;
 
 
 
void main(){
 
    assert(sizeof mystruct == 10);
 
}
 
"""
 
)
 
 
 
test("struct_size 4",
 
"""
 
 
 
typedef struct {long int a; int b[2];} mystruct;
 
 
 
void main(){
 
    assert(sizeof mystruct == 6);
 
}
 
"""
 
)
 
 
 
test("struct_passing 1",
 
"""
 
 
 
typedef struct {int a; int b;} mystruct;
 
 
 
void test(mystruct mine){
 
    assert(mine.a == 1);
 
    assert(mine.b == 2);
 
}
 
 
 
void main(){
 
    mystruct an;
 
    an.a = 1;
 
    an.b = 2;
 
    test(an);
 
}
 
"""
 
)
 
 
 
test("struct_passing 2",
 
"""
 
 
 
typedef struct {long int a; int b;} struct_1;
 
typedef struct {long int a; struct_1 b;} mystruct;
 
 
 
void test(mystruct my){
 
    assert(my.a == 1);
 
    assert(my.b.a == 2);
 
    assert(my.b.b == 3);
 
}
 
 
 
void main(){
 
    mystruct blah;
 
    blah.a = 1;
 
    blah.b.a = 2;
 
    blah.b.b = 3;
 
    test(blah);
 
}
 
"""
 
)
 
 
 
test("struct_passing 3",
 
"""
 
 
 
typedef struct {long int a; int b[10];} struct_1;
 
typedef struct {long int a; struct_1 b;} mystruct;
 
 
 
void test(mystruct my){
 
    assert(my.a == 1);
 
    assert(my.b.a == 2);
 
    assert(my.b.b[0] == 3);
 
}
 
 
 
void main(){
 
    mystruct blah;
 
    blah.a = 1;
 
    blah.b.a = 2;
 
    blah.b.b[0] = 3;
 
    test(blah);
 
}
 
"""
 
)
 
 
 
#test("struct_return 1",
 
#"""
 
#
 
#typedef struct {long int a; int b;} struct_1;
 
#
 
#struct_1 test(){
 
#    struct_1 my;
 
#    my.a = 1;
 
#    my.b = 2;
 
#    return my;
 
#}
 
#
 
#void main(){
 
#    struct_1 blah;
 
#    blah = test();
 
#    assert(blah.a == 1);
 
#    assert(blah.b == 2);
 
#}
 
#"""
 
#)
 
 
 
test("print 1",
 
"""
 
unsigned test[] = "Hello World!";
 
unsigned i=0;
 
void stdout_put_char(unsigned value){
 
    assert(test[i] == value);
 
    i++;
 
}
 
#include 
 
 
 
void main(){
 
    print_string("Hello World!");
 
}
 
"""
 
)
 
 
 
test("print 2",
 
"""
 
unsigned test[] = "12345";
 
unsigned i=0;
 
void stdout_put_char(unsigned value){
 
    assert(test[i] == value);
 
    i++;
 
}
 
#include 
 
 
 
void main(){
 
    print_decimal(12345);
 
}
 
"""
 
)
 
 
 
test("print 3",
 
"""
 
unsigned test[] = "-1234";
 
unsigned i=0;
 
void stdout_put_char(unsigned value){
 
    assert(test[i] == value);
 
    i++;
 
}
 
#include 
 
 
 
void main(){
 
    print_decimal(-1234);
 
}
 
"""
 
)
 
 
 
test("print 4",
 
"""
 
unsigned test[] = "-1";
 
unsigned i=0;
 
void stdout_put_char(unsigned value){
 
    assert(test[i] == value);
 
    i++;
 
}
 
#include 
 
 
 
void main(){
 
    print_decimal(-1);
 
}
 
"""
 
)
 
 
 
test("print 5",
 
"""
 
unsigned test[] = "7fff";
 
unsigned i=0;
 
void stdout_put_char(unsigned value){
 
    assert(test[i] == value);
 
    i++;
 
}
 
#include 
 
 
 
void main(){
 
    print_hex(0x7fff);
 
}
 
"""
 
)
 
 
 
test("print 6",
 
"""
 
unsigned test[] = "ffff";
 
unsigned i=0;
 
void stdout_put_char(unsigned value){
 
    assert(test[i] == value);
 
    i++;
 
}
 
#include 
 
 
 
void main(){
 
    print_uhex(0xffffu);
 
}
 
"""
 
)
 
 
test("unsigned divide 1",
test("unsigned divide 1",
"""
"""
void main(){
void main(){
  unsigned a = 10;
  unsigned a = 10;
  unsigned b = 5;
  unsigned b = 5;
Line 2821... Line 3582...
  int a = 12;
  int a = 12;
  myfunction()=10;
  myfunction()=10;
  return 0;
  return 0;
}
}
""")
""")
 
 
 
test_fails("error 12",
 
"""
 
 
 
typedef struct {long int a; int b;} struct_1;
 
typedef struct {long int a; struct_1 b;} mystruct;
 
 
 
void test(mystruct my){
 
    assert(mystruct.a == 1);
 
    assert(mystruct.b.a == 2);
 
    assert(mystruct.b.b == 3);
 
}
 
 
 
void main(){
 
    mystruct blah;
 
    blah.a = 1;
 
    blah.b.a = 2;
 
    blah.b.b = 3;
 
    test(blah);
 
}
 
"""
 
)
 
 
test("input 1",
test("input 1",
"""
"""
int main(){
int main(){
  int b;
  int b;
  b = input_a();
  b = input_a();
Line 2878... Line 3662...
int real_main(){
int real_main(){
  return 0;
  return 0;
}
}
""")
""")
 
 
os.system("python-coverage run -p c2verilog.py")
os.system("python-coverage run -p ../c2verilog")
os.system("python-coverage combine")
os.system("python-coverage combine")
os.system("python-coverage report")
os.system("python-coverage report")
os.system("python-coverage annotate c2verilog.py")
os.system("python-coverage annotate ../c2verilog")
os.system("python-coverage annotate compiler/parser.py")
os.system("python-coverage annotate ../chips/compiler/parser.py")
os.system("python-coverage annotate ../chips/compiler/parser.py")
os.system("python-coverage annotate ../chips/compiler/parser.py")

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.