public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
* generating type tests
@ 2007-10-12 21:18 Stan Cox
  2007-10-12 22:54 ` Andrew Cagney
  2007-10-15 16:56 ` Andrew Cagney
  0 siblings, 2 replies; 9+ messages in thread
From: Stan Cox @ 2007-10-12 21:18 UTC (permalink / raw)
  To: Frysk List

[-- Attachment #1: Type: text/plain, Size: 1299 bytes --]

Here is gen-typetests.py which can be used to generate a C type test
program and the associated java tester.  When invoked as 'python
gen-typetests.py -type' it will generate:  funit-type-entry.c and
TestTypeEntryType.java.  The tests this generates all pass with the
patches outlined below.  Checking values via 'python gen-typetests.py
-value' is in progress.  Suggestions are encouraged, including a good
way to graft this onto the make machinery.


TypeEntry.java: 
-Add getUnionType
-case DwTag.UNION_TYPE_ invoke getUnionType
-case DwTag.STRUCTURE_TYPE_ remove classType.setTypedefFIXME
-case DwTag.VOLATILE_TYPE_: new
-case DwTag.CONST_TYPE_: new

ArrayType.java:
-Add public void toPrint(String s, PrintWriter writer)
 This is to support the odd C syntax for pointer to array where the 
 pointer designation is embedded: int (* x) [2].  Using 1.5's 
 String.format would be nicer

PointerType.java:
-Add public void toPrint(String s, PrintWriter writer) 
 Similar to above to handle pointer to array

TypeDecorator.java
-special case PointerType so 'const int * x' and 'int * const x' are 
 handled properly

CompositeType.java:
-Add public void toPrint(int indentation, PrintWriter writer)
-if member is a CompositeType invoke toPrint with indentation+2
-special case pointer to array case

[-- Attachment #2: gen-typetests.py --]
[-- Type: text/x-python, Size: 21955 bytes --]

#!/usr/bin/python
import os,posix,sys
from subprocess import *
from os.path import *

########################################################################
# Manage creation of the java file
########################################################################

class j:
    def open(self,name):
        self.j_file = open("TestTypeEntry" + name.capitalize() + ".java", 'w')
        self.name = "TestTypeEntry" + name.capitalize()
    def write(self,str):
        self.j_file.write(str)
    def prologue(self,):
        self.j_file.write('''// Generated by gen-typetests.py

package frysk.debuginfo;

import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import lib.dwfl.DwarfDie;
import lib.dwfl.Dwfl;
import lib.dwfl.DwflDieBias;
import frysk.dwfl.DwflCache;
import frysk.proc.Task;
import frysk.testbed.TestLib;
import frysk.value.Type;

public class %s extends TestLib {
    private class ExpectTest {
	DebugInfoFrame frame;
	DwarfDie die;
	DwarfDie[] allDies;
	TypeEntry typeEntry;

	ExpectTest(String executable) {
	    Task task = StoppedTestTaskFactory.getStoppedTaskFromExecDir(executable);
	    frame = DebugInfoStackFactory.createVirtualStackTrace(task);
	    Dwfl dwfl;
	    long pc = frame.getAdjustedAddress();
	    dwfl = DwflCache.getDwfl(frame.getTask());
	    DwflDieBias bias = dwfl.getDie(pc);
	    die = bias.die;
	    allDies = die.getScopes(pc - bias.bias);
	    typeEntry = new TypeEntry(frame.getTask().getIsa());
	}
	
	void compareEqual(Expect[] expect, String myName) {
	     Type varType;
	    
	     for (int i = 0; i < expect.length; i++) {
		 DwarfDie varDie = die.getScopeVar(allDies, expect[i].symbol);
                 if (varDie == null)
                     System.out.println("Error: Cannot find " + expect[i].symbol);
		 assertNotNull(varDie);
		 varType = typeEntry.getType(varDie.getType());
                 System.out.println("Expect: " + expect[i].symbol + "\\n'" + expect[i].output + "'\\nGot:\\n'" + varType.toPrint() + "'");
		 assertNotNull(varType);
		 assertEquals(myName + expect[i].symbol, expect[i].output, varType.toPrint());
	     }
	}

       void compareRegex(Expect[] expect, String myName) {
	     Type varType;
	    
	     for (int i = 0; i < expect.length; i++) {
		 DwarfDie varDie = die.getScopeVar(allDies, expect[i].symbol);
		 if (varDie == null)
		     varDie = DwarfDie.getDeclCU(allDies, expect[i].symbol);
		 if (varDie == null) {
		     continue;
		 }
		 varType = typeEntry.getType(varDie.getType());
		 Pattern p = Pattern.compile(expect[i].output, Pattern.DOTALL);
		 Matcher m = p.matcher(varType.toPrint());
		 assertTrue(myName + expect[i].symbol, m.matches());
	     }
	}
    }

    private class Expect
    {
	String symbol;
	String output;
	Expect (String symbol, String expect)
	{
	    this.symbol = symbol;
	    this.output = expect;
	}
    }

    Logger logger = Logger.getLogger("frysk");

''' % self.name)
    def start_test(self,name):
        self.j_file.write('''
    public void test%s () {
        Expect [] expect  = {
''' % (name))
    def add_test(self,tool,name,type,long,decl,value):
        self.j_file.write('\t    new Expect("%s",' % name)
        if (tool == "type"):
            self.j_file.write('"%s"' % type)
        elif (tool == "value"):
            self.j_file.write('"%s"' % value)
        self.j_file.write("),\n")
        
    def end_test(self):
        self.j_file.write('''
              };

      ExpectTest expectTest = new ExpectTest("funit-scalar");
      expectTest.compareEqual(expect, "testScalar ");
    }
''')
    def epilogue(self,debug):
        self.j_file.write('''
    }
''')    

########################################################################
# Manage creation of the C file
########################################################################

class c:
    def open(self,name):
        self.c_file = open("funit-type-entry" + ".c", 'w')
    def write(self,str):
        str = str.replace("\\n","\n")
        self.c_file.write(str)
    def add_decl(self,str):
        self.c_file.write("static " + str)
    def prologue(self,):
        self.c_file.write('''// Generated by gen-typetests.py

#include <stdint.h>
#include <values.h>
#define unused __attribute__((unused))

static void
crash () {
    char *a = 0;
    a[0] = 0;
}

// Naming convention examples:
// ptr_const_char_var - Pointer to a const char
// char_ptr_const_var - Const pointer to a char
// arr_ptr_arr_arr_char - Array of pointers to 2 dimension arrays of char
// struct_arr_arr_int_var - Struct of 2 dimension arrays of int

''')
    def epilogue(self,debug):
        self.c_file.write("\n")
        if (debug):
            self.c_file.write("volatile int x = 1;\n")
        self.c_file.write("int\n")
        self.c_file.write("main (int argc, char **argv) {\n")
        if (debug):
            self.c_file.write("while (x);\n")
        self.c_file.write("    crash ();\n    return 0;\n}\n")

########################################################################
# Coordinate creation of the source files
########################################################################

class s:
    def open(self,tool):
        self.tool = tool
        self.c_file = c()
        self.c_file.open(tool)
        self.c_file.prologue()
        self.j_file = j()
        self.j_file.open(tool)
        self.j_file.prologue()
    def c_write(self,str):
        self.c_file.write(str)
    def j_write(self,str):
        self.j_file.write(str)
    def start_test(self,str):
        self.j_file.start_test(str)
    def add_test(self, name, short, long, decl, value):
        self.j_file.add_test(self.tool, name, short, long, decl, value)
    def end_test(self):
#        self.c_file.end_test()
        self.j_file.end_test()
    def add(self, type, var, type_arr, initial):
        if (type_arr == ""):
            var_suffix = "_var"
        else:
            var_suffix = ""
        source.c_file.write("static " + type + " " + var + var_suffix + type_arr)
        source.c_file.write(" unused")
        if initial != "":
            source.c_file.write(" = " + initial)
        source.c_file.write(";\n")            

        if (type_arr.startswith("[")):
            jtype = type + " " + type_arr
        else:
            jtype = type + type_arr
        jtype = jtype.rstrip()
        source.j_file.add_test(self.tool, var + var_suffix, jtype, jtype, jtype,
                               initial)
    # like add but allows expected type to be given separately
    def addexpected(self, type, etype, var, type_arr, initial):
        if (type_arr == ""):
            var_suffix = "_var"
        else:
            var_suffix = ""
        source.c_file.write("static " + type + " " + var + var_suffix + type_arr)
        source.c_file.write(" unused")
        if initial != "":
            source.c_file.write(" = " + initial)
        source.c_file.write(";\n")            

        source.j_file.add_test(self.tool, var + var_suffix, etype, etype, etype,
                               initial)
    def add_decl(self,str):
        self.c_file.write("static " + str)
#        self.j_file.write("static " + str)
    def epilogue(self):
        self.c_file.epilogue(debug)
        self.j_file.epilogue(debug)

########################################################################
# main
########################################################################

def usage ():
    print "Usage " + sys.argv[0] + " -value OR -type"
    sys.exit(1)

if (len (sys.argv) == 1):
    usage()
debug=0
for t in sys.argv:
    if (t == "-value"):
        tool="value"
    elif (t == "-type"):
        tool="type"
    elif (t == "-debug"):
        debug=1
    elif (t.startswith("-")):
        usage()

host='x86'

# Used for variable initialization
limits={'char' : {'min' : {'x86' : '41', 'x86_64' : '41'},
                  'max' : {'x86' : '176', 'x86_64' : '176'}},
        'uchar' : {'min' : {'x86' : '0', 'x86_64' : '0'},
        	  'max' : {'x86' : '255', 'x86_64' : '255'}},
        'short int' : {'min' : {'x86' : '-32767-1', 'x86_64' : '-32768'},
        	   'max' : {'x86' : '32767', 'x86_64' : '32767'}},
        'ushort' : {'min' : {'x86' : '65535', 'x86_64' : '65535'},
        	    'max' : {'x86' : '65535', 'x86_64' : '65535'}},
        'int' : {'min' : {'x86' : '-2147483647-1', 'x86_64' : '-2147483648'},
        	 'max' : {'x86' : '2147483647', 'x86_64' : '2147483647'}},
        'uint' : {'min' : {'x86' : '4294967295', 'x86_64' : '4294967295'},
        	  'max' : {'x86' : '4294967295', 'x86_64' : '4294967295'}},
        'long int' : {'min' : {'x86' : '-2147483647L-1', 'x86_64' : '-9223372036854775807L-1'},
	          'max' : {'x86' : '2147483647L', 'x86_64' : '9223372036854775807L'}},
        'ulong' : {'min' : {'x86' : '4294967295UL', 'x86_64' : '18446744073709551615UL'},
        	   'max' : {'x86' : '4294967295UL', 'x86_64' : '18446744073709551615UL'}},
        'long long int' : {'min' : {'x86' : '-9223372036854775807LL-1', 'x86_64' : '-9223372036854775807LL-1'},
        	   'max' : {'x86' : '9223372036854775807LL', 'x86_64' : '9223372036854775807LL'}},
        'ulong long' : {'min' : {'x86' : '18446744073709551615ULL', 'x86_64' : '18446744073709551615ULL'},
                        'max' : {'x86' : '18446744073709551615ULL', 'x86_64' : '18446744073709551615ULL'}},
        'float' : {'min' : {'x86' : '1.175494E-38', 'x86_64' : '1.175494E-38'},
        	   'max' : {'x86' : '3.402823E+38', 'x86_64' : '3.402823E+38'}},
        'double' : {'min' : {'x86' : '2.225074E-308', 'x86_64' : '2.225074E-308'},
        	    'max' : {'x86' : '1.797693E+308', 'x86_64' : '1.797693E+308'}},
}        

# base types we generate variables for.  used to index into limits map
base_types=('char','short int','int','long int','long long int','float','double')
type_modifiers=('const','volatile')

source = s()
source.open(tool)

tm = te = tme = tms = ""
for m in type_modifiers:
    tm = tm + m + " "
    te = " " + te + m
# gcc puts multiple types in the opposite order of source so ignore these
tm = tm.rstrip()
te = te.lstrip()
tms = tm.rstrip().replace(" ","_")
source.start_test("Scalar") ########################################
for t in base_types:
    try:
        ts = t.replace(" ","_")
        source.c_write("// %s\n" % t);
        min = limits[t]['min'][host]
        max = limits[t]['max'][host]
        source.add(t, ts, "", max)
        for m in type_modifiers:
            source.add("%s %s" % (m,t), "%s_%s" % (m,ts), "", min)
#        source.addexpected("%s %s" % (tm,t), "%s %s" % (te,t), "%s_%s" % (tms,ts), "", max)
        source.add("%s *" % t, "ptr_" + ts, "", "&%s_var" % ts)
        for m in type_modifiers:
            source.add("%s %s *" % (m,t), "ptr_%s_%s" % (m,ts), "",
                       "&%s_var" % ts)
            source.add("%s * %s" % (t,m), "%s_ptr_%s" % (ts,m), "",
                       "&%s_var" % ts)
#       source.add("%s %s *" % (tm,t), "ptr_%s_%s" % (tms,ts), "",
#                  "&%s_var" % ts)
#       source.add("%s * %s" % (t,tm), "%s_ptr_%s" % (ts,tms), "",
#                  "&%s_var" % ts)
#        if (t != "float" and t != "double"):
#            source.addexpected("unsigned %s" % t, "unsigned %s" % t, "unsigned_%s" % ts, "", max)
    except KeyError:
        continue
source.end_test()    

source.start_test("Array") ########################################
source.c_write("\n");
for t in base_types:
    source.c_write("// array of %s\n" % (t))
    ts = t.replace(" ","_")
    min = limits[t]['min'][host]
    max = limits[t]['max'][host]
    source.add(t, "arr_%s" % ts, "[2]", "{%s,%s}" % (min,max))
    source.add(t, "arr_arr_%s" % ts, "[2][2]", "{{%s,%s},{%s,%s}}" % (min,max,min,max))
    source.add(t, "arr_arr_arr_%s" % ts, "[2][2][2]", "{{{%s,%s},{%s,%s}},{{%s,%s},{%s,%s}}}" % (min,max,min,max,min,max,min,max))
    source.add("%s *" % t, "arr_ptr_arr_arr_%s" % ts, "[2]", "{arr_arr_%s[0],arr_arr_%s[1]}" % (ts,ts))
    source.add("%s (*" % t, "ptr_arr_%s" % ts, ")[2]", "&arr_%s" % ts)

# we modify \\n so c source has actual new lines and java has a \n escape
source.c_write("\\nstatic int one = 1, two = 2, three = 3, four = 4;\n")

source.add("struct {\\n  int int_var;\\n}", "arr_struct", "[2]","{{1},{2}}")
source.add("union {\\n  int int_var;\\n  float float_var;\\n}", "arr_union", "[2]", "{{1},{2}}")
source.add("struct {\\n  int int_var;\\n}", "arr_arr_struct", "[2][2]", "{{{1},{2}},{{3},{4}}}")
source.add("union {\\n  int int_var;\\n  float float_var;\\n}", "arr_arr_union", "[2][2]", "{{{1},{2}},{{3},{4}}}")
source.add("int *", "arr_arr_ptr", "[2][2]", "{{&one,&two},{&three,&four}}")
source.add("struct {\\n  int arr_int[2];\\n}", "arr_struct_arr_int", "[2]", "{{{1, 2}}, {{3, 4}}}")
source.add("struct {\\n  struct {\\n    int int_var;\\n  } struct_a;\\n}", "arr_struct_struct", "[2]", "{{{1}},{{2}}}")
source.add("struct {\\n  union {\\n    int int_var;\\n    float float_var;\\n  } struct_a;\\n}", "arr_struct_union", "[2]", "{{{1}},{{2}}}")
source.add("struct {\\n  int * ptr;\\n}", "arr_struct_ptr", "[2]", "{{&one},{&two}}")
source.add("union {\\n  int arr_int[2];\\n  float arr_float[2];\\n}", "arr_union_arr_int", "[2]", "{{{1, 2}}, {{3, 4}}}")
source.add("union {\\n  struct {\\n    int int_var;\\n  } struct_a;\\n}", "arr_union_struct", "[2]", "{{{1}}, {{2}}}")
source.add("union {\\n  union {\\n    int int_var;\\n  } union_a;\\n}", "arr_union_union", "[2]", "{{{1}}, {{2}}}")
source.add("union {\\n  int * ptr;\\n}", "arr_union_ptr", "[2]", "{{&one}, {&two}}")
# ??? fails
# source.add("int (*", "arr_ptr_arr", "[2])[2]", "{&arr_int, &arr_int}")
source.add("struct {\\n  int int_var;\\n} *", "arr_ptr_struct", "[2]", "")
source.add("union {\\n  int int_var;\\n  float float_var;\\n} *", "arr_ptr_union", "[2]", "")
source.add("int * *", "arr_ptr_ptr", "[2]", "")
source.add("struct {\\n  int int_var;\\n} (*", "ptr_arr_struct", ")[2]","")
source.add("union {\\n  int int_var;\\n} (*", "ptr_arr_union", ")[2]", "")
source.add("int * (*", "ptr_arr_ptr", ")[2]", "")
source.end_test()    

source.start_test("Struct") ########################################
source.c_write('''typedef struct {
    char char_var;
    short short_var;
    int int_var;
    long long_var;
    float float_var;
    double double_var;
    char arr_char[4];
} type_struct;
typedef struct {
    type_struct type_struct_min;
    type_struct type_struct_max;
} type_type_struct;
type_type_struct type_minmax_struct =
  {{%s, %s, %s, %s, %s, %s, %s},
   {%s, %s, %s, %s, %s, %s, %s}
};\n''' % (limits['char']['min'][host],limits['short int']['min'][host],limits['int']['min'][host],limits['long int']['min'][host],limits['float']['min'][host],limits['double']['min'][host],'"ABC"',limits['char']['max'][host],limits['short int']['max'][host],limits['int']['max'][host],limits['long int']['max'][host],limits['float']['max'][host],limits['double']['max'][host],'"XYZ"'))
source.add('''struct {\\n  unsigned int bit1_0:1;\\n  unsigned int bit1_1:1;\\n  char char_2;\\n  unsigned int bit1_6:1;\\n  unsigned int bit1_7:1;\\n  char char_8;\\n  unsigned int bit1_9:1;\\n  unsigned int bit1_10:1;\\n}''', "bitfields_small", "", "{1, 0, 0x7f, 1, 0, 0x7f, 1, 0}")
source.add('''struct {\\n  unsigned char char_0;\\n  int bit1_4:1;\\n  unsigned int bit1_5:1;\\n  int bit2_6:2;\\n  unsigned int bit2_8:2;\\n  int bit3_10:3;\\n  unsigned int bit3_13:3;\\n  int bit9_16:9;\\n  unsigned int bit9_25:9;\\n  char char_34;\\n}''', "bitfields_bit", "",  "{0x7f, 1, 1, 1, 3, 3, 7, UINT8_MAX, 511, 0x7f}")
source.add('''struct {\\n  short int arr_short[2];\\n}''', "struct_arr_short", "",  "{{1, 2}}")
source.add('''struct {\\n  struct {\\n    int int_var;\\n  } struct_a;\\n}''', "struct_struct", "",  "{{1}}")
source.add("struct {\\n  union {\\n    int int_var;\\n  } union_a;\\n}", "struct_union", "", "{{1}}")
source.add('''struct {\\n  int * ptr_int;\\n}''', "struct_ptr", "",  "{&one}")
source.add('''union {\\n  int arr_int[4];\\n  float arr_float[4];\\n}''', "union_arr", "", "{{1, 2, 3, 4}}")
source.add('''union {\\n  struct {\\n    int int_var;\\n  } struct_a;\\n}''', "union_struct", "", "{{1}}")
source.add('''union {\\n  union {\\n    int int_var;\\n    float float_var;\\n  } union_a;\\n}''', "union_union", "", "{{1}}")
source.add('''union {\\n  int * ptr_int;\\n}''', "union_ptr", "", "{&one}")
source.add('''struct {\\n  int int_var;\\n} *''', "ptr_struct", "", "")
source.add('''union {\\n  int int_var;\\n} *''', "ptr_union", "", "")
source.add('''struct {\\n  int arr_arr_int[2][2];\\n}''', "struct_arr_arr_int", "", "{{{1, 2}, {3, 4}}}")
# ??? improve indentation
source.add('''struct {\\n  struct {\\n  int int_var;\\n} arr_struct[2];\\n}''', "struct_arr_struct", "", "{{{1}, {2}}}")
source.add('''struct {\\n  union {\\n  int int_var;\\n} arr_union[4];\\n}''', "struct_arr_union", "", "{{{1}, {2}}}")
source.add('''struct {\\n  int * arr_ptr[2];\\n}''', "struct_arr_ptr", "", "{{&one, &two}}")
source.add('''struct {\\n  struct {\\n    int arr_int[2];\\n  } struct_arr;\\n}''', "struct_struct_arr_int", "", "{{{1, 2}}}")
source.add('''struct {\\n  struct {\\n    struct {\\n      int int_var;\\n    } struct_a;\\n  } struct_struct;\\n}''', "struct_struct_struct", "", "{{{1}}}")
source.add('''struct {\\n  struct {\\n    union {\\n      char int_var;\\n    } union_a;\\n  } struct_union;\\n}''', "struct_struct_union", "", "{{{1}}}")
source.add('''struct {\\n  struct {\\n    int * ptr_int;\\n  } sp;\\n}''', "struct_struct_ptr", "", "{{&three}}")
source.add('''struct {\\n  union {\\n    int arr_int[4];\\n  } union_arr_int;\\n}''', "struct_union_arr", "",  "{{{1, 2, 3, 4}}}")
source.add('''struct {\\n  union {\\n    struct {\\n      int int_var;\\n    } struct_a;\\n  } union_struct;\\n}''', "struct_union_struct", "", "{{{1}}}")
source.add('''struct {\\n  union {\\n    union {\\n      long int int_var;\\n      float float_var;\\n    } union_a;\\n  } union_union;\\n}''', "struct_union_union", "", "{{{1.0}}}")
source.add('''struct {\\n  union {\\n    int * ptr_int;\\n  } union_ptr;\\n}''', "struct_union_ptr", "", "{{&four}}")
source.add('''struct {\\n  int (* ptr_arr)[4];\\n}''', "struct_ptr_arr", "", "")
# ??? improve indentation
source.add('''struct {\\n  struct {\\n  int int_var;\\n} * ptr_struct;\\n}''', "struct_ptr_struct", "", "")
source.add('''struct {\\n  union {\\n  int int_var;\\n} * ptr_union;\\n}''', "struct_ptr_union", "", "")
source.add('''struct {\\n  int * * ptr_ptr;\\n}''', "struct_ptr_ptr", "", "")
source.add('''union {\\n  int arr_int[2][2];\\n  float arr_float[2][2];\\n}''', "union_arr_int", "", "{{{1, 2}, {3, 4}}}")
# ??? improve indentation
source.add('''union {\\n  struct {\\n  int int_var;\\n} arr_struct[2];\\n}''', "union_arr_struct", "", "{{{1}}}")
source.add('''union {\\n  union {\\n  int int_var;\\n  float float_var;\\n} arr_union[2];\\n}''', "union_arr_union", "", "{{{1.1}}}")
source.add('''union {\\n  int * arr_ptr[4];\\n}''', "union_arr_ptr", "", "{{&one}}")
source.add('''union {\\n  struct {\\n    int arr_int[4];\\n  } struct_arr;\\n}''', "union_struct_arr_int", "", "{{{1, 2, 3, 4}}}")
source.add('''union {\\n  struct {\\n    struct {\\n      int int_var;\\n    } struct_a;\\n  } struct_b;\\n}''', "union_struct_struct", "", "{{{1}}}")
source.add('''union {\\n  struct {\\n    union {\\n      int int_var;\\n      float float_var;\\n    } union_a;\\n  } struct_a;\\n}''', "union_struct_union", "", "{{{1.1}}}")
source.add('''union {\\n  struct {\\n    int * ptr_int;\\n  } struct_ptr;\\n}''', "union_struct_ptr", "", "{{&one}}")
source.add('''union {\\n  union {\\n    long long int arr_int[4];\\n  } union_arr;\\n}''', "union_union_arr_int", "", "{{{1, 2, 3, 4}}}")
source.add('''union {\\n  union {\\n    struct {\\n      long long int int_var;\\n    } struct_a;\\n  } union_a;\\n}''', "union_union_struct", "", "{{{1}}}")
source.add('''union {\\n  union {\\n    union {\\n      int int_var;\\n      float float_var;\\n    } union_a;\\n  } union_b;\\n}''', "union_union_union", "", "{{{1.1}}}")
source.add('''union {\\n  union {\\n    int * ptr_int;\\n    float * ptr_float;\\n  } union_ptr;\\n}''', "union_union_ptr", "", "{{&one}}")
source.add('''union {\\n  int (* ptr_arr)[4];\\n}''', "union_ptr_arr", "", "")
source.add('''union {\\n  struct {\\n  int int_var;\\n} * ptr_struct;\\n}''', "union_ptr_struct", "", "")
source.add('''union {\\n  union {\\n  int int_var;\\n} * ptr_union;\\n}''', "union_ptr_union", "", "")
source.add('''union {\\n  int * * ptr_ptr;\\n}''', "union_ptr_ptr", "", "")
source.add('''struct {\\n  int arr_int[4];\\n} *''', "ptr_struct_arr_int", "", "")
source.add('''struct {\\n  struct {\\n    int int_var;\\n  } struct_a;\\n} *''', "ptr_struct_struct", "", "")
source.add('''struct {\\n  union {\\n    int int_var;\\n  } union_a;\\n} *''', "ptr_struct_union", "", "")
source.add('''struct {\\n  int * ptr_int;\\n} *''', "ptr_struct_ptr", "", "")
source.add('''union {\\n  int arr_int[4];\\n} *''',"ptr_union_arr_int", "", "")
source.add('''union {\\n  struct {\\n    int int_var;\\n  } struct_a;\\n} *''',"ptr_union_struct", "", "")
source.add('''union {\\n  union {\\n    int int_var;\\n  } union_a;\\n} *''', "ptr_union_union", "", "")
source.add('''union {\\n  int * ptr_int;\\n} *''', "ptr_union_ptr", "", "")
source.add('''struct {\\n  int int_var;\\n} * *''', "ptr_ptr_struct", "", "")
source.add('''union {\\n  int int_var;\\n} * *''', "ptr_ptr_union", "", "")
source.end_test()

source.start_test("Enum") ########################################
source.add('''enum  {\\n  red = 0,\\n  green = 1,\\n  blue = 2\\n}''', "primary_colors", "", "")
source.add('''enum colors {\\n  orange = 0,\\n  yellow = 1,\\n  violet = 2,\\n  indigo = 3\\n}''', "rainbow_colors", "", "")
source.add('''enum  {\\n  chevy = 33,\\n  dodge = 44,\\n  ford = 55\\n}''', "usa_cars", "", "")
source.add('''enum cars {\\n  bmw = 0,\\n  mercedes = 1,\\n  porsche = 2\\n}''', "european_cars", "", "")
source.end_test()

source.epilogue()

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: generating type tests
  2007-10-12 21:18 generating type tests Stan Cox
@ 2007-10-12 22:54 ` Andrew Cagney
  2007-10-15  2:10   ` Stan Cox
  2007-10-15 16:56 ` Andrew Cagney
  1 sibling, 1 reply; 9+ messages in thread
From: Andrew Cagney @ 2007-10-12 22:54 UTC (permalink / raw)
  To: Stan Cox; +Cc: Frysk List

My hunch it is trying to do too much - simultaneously acting as both 
filter and generator.  For instance:
-> structs is created from a brute force table
-> scalars is generated using a for loop
would it be better to separate these steps out, perhaps also having a 
separate data file, then this can be implemented as one or more filters.

As things advance, will the types that need to be tested become too 
complex for this scripting technique?  For instance:
    struct foo { int i; } f = { 1 };
    struct bar { struct foo* f; struct bar *b;};
    struct bar b = { NULL, NULL }
    struct bar bp = { &f, &b };
I wonder if letting the user describe the types in C, and output in 
comments, and then filter that to generate the tests is better?  Vis:
    // TEST: bp
    // TYPE: struct bar { struct foo *f; struct bar *b}
    // VALUE: { 0x.*, 0x.* }
    // STYPE: struct bar
is going to be easier to work on.  Similarly, chosing simple values may 
make it easier.

Andrew




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: generating type tests
  2007-10-12 22:54 ` Andrew Cagney
@ 2007-10-15  2:10   ` Stan Cox
  2007-10-15 16:50     ` Andrew Cagney
  0 siblings, 1 reply; 9+ messages in thread
From: Stan Cox @ 2007-10-15  2:10 UTC (permalink / raw)
  To: Frysk List

< simultaneously acting as both filter and generator.  For instance:
> -> structs is created from a brute force table
> -> scalars is generated using a for loop

One advantage of the brute force approach is that it ensures that any
combination, that is programmed into the tool of course, will be
tested without having to explicitly list them.


> would it be better to separate these steps out, perhaps also having a 
> separate data file, then this can be implemented as one or more
filters.

So it seems to me that an implicit brute force tester is useful perhaps
in
addition to an explicit tester.  I like the idea of a
generator though.  My initial thought was an input file that used
cdecl syntax.  For example cdecl allows 'declare x as array of array
of int' but doesn't support any struct syntax so scratch that.

> As things advance, will the types that need to be tested become too 
> complex for this scripting technique?  For instance:
>    struct foo { int i; } f = { 1 };
> ...
> I wonder if letting the user describe the types in C, and output in 
> comments, and then filter that to generate the tests is better?  Vis:

(BTW, I can test these now, e.g. source.add("struct foo {\\n
int i;\\n}", "f", "","{1}"))  It would certainly be possible to read
in declarations from a file and produce the equivalent C and java
support code.  I'm not sure I am following what the advantage of using
the filers is though, as opposed to producing the C and java directly
from the input file.

> is going to be easier to work on.  Similarly, chosing simple values
may 
> make it easier.

Reminds me of the Einstein aphorism, make things as simple as possible
but no simpler!




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: generating type tests
  2007-10-15  2:10   ` Stan Cox
@ 2007-10-15 16:50     ` Andrew Cagney
  2007-10-16 19:47       ` Stan Cox
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Cagney @ 2007-10-15 16:50 UTC (permalink / raw)
  To: Stan Cox; +Cc: Frysk List

Stan Cox wrote:
> < simultaneously acting as both filter and generator.  For instance:
>   
>> -> structs is created from a brute force table
>> -> scalars is generated using a for loop
>>     
>
> One advantage of the brute force approach is that it ensures that any
> combination, that is programmed into the tool of course, will be
> tested without having to explicitly list them.
>
>
>   
>> would it be better to separate these steps out, perhaps also having a 
>> separate data file, then this can be implemented as one or more
>>     
> filters.
>
> So it seems to me that an implicit brute force tester is useful perhaps
> in
> addition to an explicit tester.  I like the idea of a
> generator though.  My initial thought was an input file that used
> cdecl syntax.  For example cdecl allows 'declare x as array of array
> of int' but doesn't support any struct syntax so scratch that.
>
>   
>> As things advance, will the types that need to be tested become too 
>> complex for this scripting technique?  For instance:
>>    struct foo { int i; } f = { 1 };
>>     
The original example was a little more complex vis:

   struct foo { int i; } f = { 1 };
   struct bar { struct foo* f; struct bar *b;};
   struct bar b = { NULL, NULL }
   struct bar bp = { &f, &b };

while it might be possible to generate even this, I believe it is going 
to be much easier for future developers if they only need to read/edit a 
simple text (.c) file to add additional type tests.  The expected 
results could be marked with comments:

   // LTYPE: struct bar {
   // LTYPE:   struct foo *f;
   // LTYPE:   struct bar *b;
   // LTYPE: }
   // VALUE: { 0x.*, 0x.* }
   // STYPE: struct bar
   // TEST: bp

and a page of AWK could translate that into the body of a test.

For the easy cases, can the generator produce a file like that; giving 
us the two steps:

   generator > simple.c
   filter < simple.c > Test.java

breaking a large program down into a set of filters gives us smaller 
simpler programs with more clearly defined steps

Andrew


>> ...
>> I wonder if letting the user describe the types in C, and output in 
>> comments, and then filter that to generate the tests is better?  Vis:
>>     
>
> (BTW, I can test these now, e.g. source.add("struct foo {\\n
> int i;\\n}", "f", "","{1}"))  It would certainly be possible to read
> in declarations from a file and produce the equivalent C and java
> support code.  I'm not sure I am following what the advantage of using
> the filers is though, as opposed to producing the C and java directly
> from the input file.
>
>   
>> is going to be easier to work on.  Similarly, chosing simple values
>>     
> may 
>   
At present there's a chunk of code concerned with generating and 
assigning max values.  If we choose simple values, and assume that int 
is at least 32-bits, that code isn't needed.

>> make it easier.
>>     
>
> Reminds me of the Einstein aphorism, make things as simple as possible
> but no simpler!
>
>
>
>
>   

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: generating type tests
  2007-10-12 21:18 generating type tests Stan Cox
  2007-10-12 22:54 ` Andrew Cagney
@ 2007-10-15 16:56 ` Andrew Cagney
  2007-10-15 19:13   ` Stan Cox
  2007-10-18 16:16   ` Stan Cox
  1 sibling, 2 replies; 9+ messages in thread
From: Andrew Cagney @ 2007-10-15 16:56 UTC (permalink / raw)
  To: Stan Cox; +Cc: Frysk List

Stan Cox wrote:
> TypeEntry.java: 
> -Add getUnionType
> -case DwTag.UNION_TYPE_ invoke getUnionType
> -case DwTag.STRUCTURE_TYPE_ remove classType.setTypedefFIXME
> -case DwTag.VOLATILE_TYPE_: new
> -case DwTag.CONST_TYPE_: new
>
> ArrayType.java:
> -Add public void toPrint(String s, PrintWriter writer)
>  This is to support the odd C syntax for pointer to array where the 
>  pointer designation is embedded: int (* x) [2].  Using 1.5's 
>  String.format would be nicer
>
> PointerType.java:
> -Add public void toPrint(String s, PrintWriter writer) 
>  Similar to above to handle pointer to array
>
> TypeDecorator.java
> -special case PointerType so 'const int * x' and 'int * const x' are 
>  handled properly
>
> CompositeType.java:
> -Add public void toPrint(int indentation, PrintWriter writer)
> -if member is a CompositeType invoke toPrint with indentation+2
> -special case pointer to array case
>   
Can you post the patch?  If you see an apparent need to add C specific 
"special cases" then there might have a problem with the code.  
Especially when frysk needs to be able to handle more than just C/C++.  
Time for the tree/visitor pattern?

Andrew

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: generating type tests
  2007-10-15 16:56 ` Andrew Cagney
@ 2007-10-15 19:13   ` Stan Cox
  2007-10-18 16:16   ` Stan Cox
  1 sibling, 0 replies; 9+ messages in thread
From: Stan Cox @ 2007-10-15 19:13 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Frysk List

[-- Attachment #1: Type: text/plain, Size: 426 bytes --]

On Mon, 2007-10-15 at 12:54 -0400, Andrew Cagney wrote:
> Can you post the patch?

(Note: this is a "make it work" patch.)
ArrayType:     Handle 'int (*x) [N]'
               Actually we probably want to display it as 'int (*) [N}'
               (minus the name)
PointerType:   Handle 'int (*x) []'
CompositeType: Handle 'struct {struct {..}}' and 'int (*x) []'
TypeDecorator: Handle 'const int * x' versus 'int * const x'



[-- Attachment #2: ,cvsdiff --]
[-- Type: text/plain, Size: 5889 bytes --]


===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/value/ArrayType.java,v
retrieving revision 1.37
diff -u -p -r1.37 ArrayType.java
--- value/ArrayType.java	6 Sep 2007 14:26:09 -0000	1.37
+++ value/ArrayType.java	12 Oct 2007 20:37:02 -0000
@@ -204,14 +204,17 @@ public class ArrayType
 	}
     }
 
-    public void toPrint(PrintWriter writer) {
+    public void toPrint(String s, PrintWriter writer) {
 	type.toPrint(writer);
-	writer.print(" [");
+	writer.print(" " + s);
 	for(int i = 0; i < this.dimension.length; i++) {
-	    if (i > 0)
-		writer.print(",");
+	    writer.print("[");
 	    writer.print(dimension[i]);
+	    writer.print("]");
 	}
-	writer.print("]");
+    }
+    
+    public void toPrint(PrintWriter writer) {
+	this.toPrint("", writer);
     }
 }
Index: value/CompositeType.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/value/CompositeType.java,v
retrieving revision 1.2
diff -u -p -r1.2 CompositeType.java
--- value/CompositeType.java	6 Sep 2007 20:48:09 -0000	1.2
+++ value/CompositeType.java	12 Oct 2007 20:37:02 -0000
@@ -259,16 +261,21 @@ abstract class CompositeType
 	writer.print("}");
     }
 
-    public void toPrint(PrintWriter writer) {
+    public void toPrint(int indentation, PrintWriter writer) {
 	// FIXME: going away.
 	if (this.isTypedef() && this.getName() != null
-	    && this.getName().length() > 0) {
+		&& this.getName().length() > 0) {
 	    writer.print(this.getName());
 	    return;
 	}
+
+	String indentPrefix = "";
+	for (int indent = 1; indent <= indentation; indent++)
+	    indentPrefix = indentPrefix + " ";
+
 	// {class,union,struct} NAME
 	writer.print(getPrefix());
-	if (getName() != null) {
+	if (getName() != null && getName().length() > 0) {
 	    writer.print(" ");
 	    writer.print(getName());
 	}
@@ -278,7 +285,7 @@ abstract class CompositeType
 	Iterator i = members.iterator();
 	// Types this inherits come first; print them out.
 	while (i.hasNext()) {
-	    member = (Member)i.next();
+	    member = (Member) i.next();
 	    if (!member.inheritance)
 		break;
 	    if (first) {
@@ -289,7 +296,6 @@ abstract class CompositeType
 	    }
 	    if (member.access != null) {
 		writer.print(member.access.toPrint());
-		writer.print(" ");
 	    }
 	    writer.print(member.type.getName());
 	    member = null;
@@ -297,7 +303,9 @@ abstract class CompositeType
 	// { content ... }
 	Access previousAccess = null;
 	writer.print(" {\n");
+
 	while (member != null) {
+	    boolean printName = true;
 	    if (member.access != previousAccess) {
 		previousAccess = member.access;
 		if (member.access != null) {
@@ -306,12 +314,25 @@ abstract class CompositeType
 		    writer.print(":\n");
 		}
 	    }
-	    writer.print("  ");
-	    if (member.type.isTypedef())
+	    writer.print(indentPrefix);
+	    
+	    if (member.type instanceof TypeDef)
 		writer.print(member.type.getName());
+	    else if (member.type instanceof CompositeType)
+		((CompositeType) member.type).toPrint(indentation + 2, writer);
+	    else if (member.type instanceof ArrayType) {
+		printName = false;
+		((ArrayType) member.type).toPrint(member.name, writer);
+	    }
+	    else if (member.type instanceof PointerType) {
+		printName = false;
+		((PointerType) member.type).toPrint(" " + member.name, writer);
+	    }
 	    else
 		member.type.toPrint(writer);
-	    if (!(member.type instanceof frysk.value.FunctionType)) {
+	    if (member.type instanceof frysk.value.FunctionType)
+		printName = false;
+	    if (printName) {
 		writer.print(" ");
 		writer.print(member.name);
 	    }
@@ -322,10 +343,16 @@ abstract class CompositeType
 	    writer.print(";\n");
 	    // Advance
 	    if (i.hasNext())
-		member = (Member)i.next();
+		member = (Member) i.next();
 	    else
 		member = null;
 	}
+	for (int indent = 1; indent <= indentation - 2; indent++)
+	    writer.print(" ");
 	writer.print("}");
     }
+
+    public void toPrint(PrintWriter writer) {
+	this.toPrint(2, writer);
+    }
 }
Index: value/PointerType.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/value/PointerType.java,v
retrieving revision 1.23
diff -u -p -r1.23 PointerType.java
--- value/PointerType.java	21 Sep 2007 20:21:07 -0000	1.23
+++ value/PointerType.java	12 Oct 2007 20:37:02 -0000
@@ -93,11 +93,20 @@ public class PointerType
 	}
     }
 
-    public void toPrint(PrintWriter writer) {
-	type.toPrint(writer);
-	writer.print(" *");
+    public void toPrint(String s, PrintWriter writer) {
+	if (type instanceof ArrayType) {
+	    ((ArrayType)type).toPrint("(*" + s + ")", writer);
+	}
+	else {
+	    type.toPrint(writer);
+	    writer.print(" *" + s);
+	}
     }
 
+    public void toPrint(PrintWriter writer) {
+	this.toPrint("", writer);
+    }
+    
     protected Type clone(IntegerType accessor) {
 	return new PointerType(getName(), order(), getSize(), type, accessor);
     }


Index: value/TypeDecorator.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/value/TypeDecorator.java,v
retrieving revision 1.5
diff -u -p -r1.5 TypeDecorator.java
--- value/TypeDecorator.java	6 Sep 2007 03:19:07 -0000	1.5
+++ value/TypeDecorator.java	12 Oct 2007 20:37:02 -0000
@@ -77,9 +77,14 @@ abstract class TypeDecorator extends Typ
      * A guess; sub classes should override.
      */
     public void toPrint(PrintWriter writer) {
-	writer.print(getName());
-	writer.print(" ");
-	decorated.toPrint(writer);
+	if (getUltimateType() instanceof PointerType) {
+	    decorated.toPrint(writer);
+	    writer.print(" " + getName());
+	}
+	else {
+	    writer.print(getName() + " ");
+	    decorated.toPrint(writer);
+	}
     }
     public Value add(Value var1, Value var2) {
 	return decorated.add(var1, var2);

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: generating type tests
  2007-10-15 16:50     ` Andrew Cagney
@ 2007-10-16 19:47       ` Stan Cox
  2007-10-17 11:12         ` Stan Cox
  0 siblings, 1 reply; 9+ messages in thread
From: Stan Cox @ 2007-10-16 19:47 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Frysk List

[-- Attachment #1: Type: text/plain, Size: 856 bytes --]

On Mon, 2007-10-15 at 12:49 -0400, Andrew Cagney wrote:
> if they only need to read/edit a 
> simple text (.c) file to add additional type tests.  The expected 
> results could be marked with comments:

>    // LTYPE: struct bar {
>    // LTYPE:   struct foo *f;
>    // LTYPE:   struct bar *b;
>    // LTYPE: }
>    // VALUE: { 0x.*, 0x.* }
>    // STYPE: struct bar
>    // TEST: bp
> 
> and a page of AWK could translate that into the body of a test.
> 
> For the easy cases, can the generator produce a file like that; 

I interpreted this as "create a generator that produces output like the
above from C source.  This python script pretty much does that from an
input file of C source.  I think it is reasonably solid, but as per the
meeting discussion if the preference is to have a tightly defined input
file syntax instead then that is okay too.


[-- Attachment #2: gen-typetests.py --]
[-- Type: text/x-python, Size: 3178 bytes --]

#!/usr/bin/python
import os,posix,sys
import re
from subprocess import *
from os.path import *

def usage ():
    print "Usage: " + sys.argv[0] + " {-help} File"
    sys.exit(1)

def get_dcl ():
    get_a_line = True
    dcl = ""
    semi_count = 0
    while (get_a_line):
        line = d_file.readline()
        if (line == ""):
            break
        if (line.lstrip().find("//") >= 0):
            continue
        dcl = dcl + line
        for c in line:
            if (c == '{'):
                semi_count += 1
            elif (c == '}'):
                semi_count -= 1
        if (semi_count == 0 and re.compile("^.*; *$").match(line)):
            break
    return dcl

if (len (sys.argv) == 1):
    usage()
if (sys.argv[1] == "-help"):
    print "The input file contains C declarations that are converted to tests."
    print "The following declaration forms are recognized:"
    print "basic_type string = initial;"
    print "type string [N]... = {initial};"
    print "type (* string) [N]... = initial;"
    print "struct string {initial};"
    print "struct string string = {initial};"
    print "enum string {initial};"
    usage()

d_file = open(sys.argv[1], 'r')
if (d_file == 0):
    usage()
    
dcl = get_dcl()
types = {'char': "char", 'short': "short", 'int': "int", 'long': "long",
         'long long': "long long", 'float': "float", 'double': "double"}

while (dcl != ""):
    dcl = dcl.rstrip()
    initial = ""
    if (dcl.find("=") == -1 or dcl.find("enum") >= 0):
        dcl_end = len(dcl)
    else:
        dcl_end = dcl.find("=")-1
    print "\nDcl: " + dcl.rstrip()[0:dcl_end]
    have_arr_ptr = re.compile("\( *\*.*\)").search(dcl)
# struct bar b = { 0, 0 };
    have_struct_type = re.compile("^\s*(struct|union).*{.*};").search(dcl) and dcl.find("=") == -1
    have_typedef = False
    have_initial = dcl.find("=") >= 0 and dcl.find("enum") == -1
    dcl = dcl.rstrip(';')
    if (have_struct_type):
        tokens = dcl.split()
        name = tokens[0] + " " + tokens[1]
        dcl = re.compile("\s*struct\s*\w+\s+").sub("",dcl,1)

    elif (have_arr_ptr):
        name = have_arr_ptr.group(0)
        name = name[2:len(name)-1].strip()
        dcl = re.compile("\s" + name + "\s").sub(" ",dcl,1)
    else: 
        tokens = dcl.split()
        previous = ""
        name = tokens[len(tokens)-1]
        if (have_initial):
            for t in tokens:
                if (t == "="):
                    name = previous
                    initial = dcl[dcl.find("="):]
                    break
                previous = t
        if (tokens[0] == "typedef"):
            have_typedef = True

        if name.find('[') >= 0:
            name = name[0:name.find('[')]
        dcl = re.compile("\s+" + name + "[^\w]").sub(" ",dcl,1)
    print "Name: " + name
    print "Initial: " + initial.lstrip("=").strip().strip(";")
    dcl = dcl.replace(initial,"").strip()
    dcl = re.compile("\s*(static|extern|typedef)\s*").sub("",dcl,1)
    print "Type: " + dcl
    if (have_struct_type or have_typedef):
        types[name] = dcl
    try:
        print "Expanded Type:" + types[dcl]
    except KeyError:
        True
    
    dcl = get_dcl()

[-- Attachment #3: sample-types.txt --]
[-- Type: text/plain, Size: 14362 bytes --]

struct foo { int i; } f = { 1 };
struct bar { struct foo* f; struct bar *b;};
struct bar b = { 0, 0 };
struct bar bp = { &f, &b };
// char
static char char_var  = 176;
static const char const_char_var  = 41;
static volatile char volatile_char_var  = 41;
static char * ptr_char_var  = &char_var;
static const char * ptr_const_char_var  = &char_var;
static char * const char_ptr_const_var  = &char_var;
static volatile char * ptr_volatile_char_var  = &char_var;
static char * volatile char_ptr_volatile_var  = &char_var;
// short int
static short int short_int_var  = 32767;
static const short int const_short_int_var  = -32767-1;
static volatile short int volatile_short_int_var  = -32767-1;
static short int * ptr_short_int_var  = &short_int_var;
static const short int * ptr_const_short_int_var  = &short_int_var;
static short int * const short_int_ptr_const_var  = &short_int_var;
static volatile short int * ptr_volatile_short_int_var  = &short_int_var;
static short int * volatile short_int_ptr_volatile_var  = &short_int_var;
// int
static int int_var  = 2147483647;
static const int const_int_var  = -2147483647-1;
static volatile int volatile_int_var  = -2147483647-1;
static int * ptr_int_var  = &int_var;
static const int * ptr_const_int_var  = &int_var;
static int * const int_ptr_const_var  = &int_var;
static volatile int * ptr_volatile_int_var  = &int_var;
static int * volatile int_ptr_volatile_var  = &int_var;
// long int
static long int long_int_var  = 2147483647L;
static const long int const_long_int_var  = -2147483647L-1;
static volatile long int volatile_long_int_var  = -2147483647L-1;
static long int * ptr_long_int_var  = &long_int_var;
static const long int * ptr_const_long_int_var  = &long_int_var;
static long int * const long_int_ptr_const_var  = &long_int_var;
static volatile long int * ptr_volatile_long_int_var  = &long_int_var;
static long int * volatile long_int_ptr_volatile_var  = &long_int_var;
// long long int
static long long int long_long_int_var  = 9223372036854775807LL;
static const long long int const_long_long_int_var  = -9223372036854775807LL-1;
static volatile long long int volatile_long_long_int_var  = -9223372036854775807LL-1;
static long long int * ptr_long_long_int_var  = &long_long_int_var;
static const long long int * ptr_const_long_long_int_var  = &long_long_int_var;
static long long int * const long_long_int_ptr_const_var  = &long_long_int_var;
static volatile long long int * ptr_volatile_long_long_int_var  = &long_long_int_var;
static long long int * volatile long_long_int_ptr_volatile_var  = &long_long_int_var;
// float
static float float_var  = 3.402823E+38;
static const float const_float_var  = 1.175494E-38;
static volatile float volatile_float_var  = 1.175494E-38;
static float * ptr_float_var  = &float_var;
static const float * ptr_const_float_var  = &float_var;
static float * const float_ptr_const_var  = &float_var;
static volatile float * ptr_volatile_float_var  = &float_var;
static float * volatile float_ptr_volatile_var  = &float_var;
// double
static double double_var  = 1.797693E+308;
static const double const_double_var  = 2.225074E-308;
static volatile double volatile_double_var  = 2.225074E-308;
static double * ptr_double_var  = &double_var;
static const double * ptr_const_double_var  = &double_var;
static double * const double_ptr_const_var  = &double_var;
static volatile double * ptr_volatile_double_var  = &double_var;
static double * volatile double_ptr_volatile_var  = &double_var;

// array of char
static char arr_char[2]  = {41,176};
static char arr_arr_char[2][2]  = {{41,176},{41,176}};
static char arr_arr_arr_char[2][2][2]  = {{{41,176},{41,176}},{{41,176},{41,176}}};
static char * arr_ptr_arr_arr_char[2]  = {arr_arr_char[0],arr_arr_char[1]};
static char (* ptr_arr_char)[2]  = &arr_char;
// array of short int
static short int arr_short_int[2]  = {-32767-1,32767};
static short int arr_arr_short_int[2][2]  = {{-32767-1,32767},{-32767-1,32767}};
static short int arr_arr_arr_short_int[2][2][2]  = {{{-32767-1,32767},{-32767-1,32767}},{{-32767-1,32767},{-32767-1,32767}}};
static short int * arr_ptr_arr_arr_short_int[2]  = {arr_arr_short_int[0],arr_arr_short_int[1]};
static short int (* ptr_arr_short_int)[2]  = &arr_short_int;
// array of int
static int arr_int[2]  = {-2147483647-1,2147483647};
static int arr_arr_int[2][2]  = {{-2147483647-1,2147483647},{-2147483647-1,2147483647}};
static int arr_arr_arr_int[2][2][2]  = {{{-2147483647-1,2147483647},{-2147483647-1,2147483647}},{{-2147483647-1,2147483647},{-2147483647-1,2147483647}}};
static int * arr_ptr_arr_arr_int[2]  = {arr_arr_int[0],arr_arr_int[1]};
static int (* ptr_arr_int)[2]  = &arr_int;
// array of long int
static long int arr_long_int[2]  = {-2147483647L-1,2147483647L};
static long int arr_arr_long_int[2][2]  = {{-2147483647L-1,2147483647L},{-2147483647L-1,2147483647L}};
static long int arr_arr_arr_long_int[2][2][2]  = {{{-2147483647L-1,2147483647L},{-2147483647L-1,2147483647L}},{{-2147483647L-1,2147483647L},{-2147483647L-1,2147483647L}}};
static long int * arr_ptr_arr_arr_long_int[2]  = {arr_arr_long_int[0],arr_arr_long_int[1]};
static long int (* ptr_arr_long_int)[2]  = &arr_long_int;
// array of long long int
static long long int arr_long_long_int[2]  = {-9223372036854775807LL-1,9223372036854775807LL};
static long long int arr_arr_long_long_int[2][2]  = {{-9223372036854775807LL-1,9223372036854775807LL},{-9223372036854775807LL-1,9223372036854775807LL}};
static long long int arr_arr_arr_long_long_int[2][2][2]  = {{{-9223372036854775807LL-1,9223372036854775807LL},{-9223372036854775807LL-1,9223372036854775807LL}},{{-9223372036854775807LL-1,9223372036854775807LL},{-9223372036854775807LL-1,9223372036854775807LL}}};
static long long int * arr_ptr_arr_arr_long_long_int[2]  = {arr_arr_long_long_int[0],arr_arr_long_long_int[1]};
static long long int (* ptr_arr_long_long_int)[2]  = &arr_long_long_int;
// array of float
static float arr_float[2]  = {1.175494E-38,3.402823E+38};
static float arr_arr_float[2][2]  = {{1.175494E-38,3.402823E+38},{1.175494E-38,3.402823E+38}};
static float arr_arr_arr_float[2][2][2]  = {{{1.175494E-38,3.402823E+38},{1.175494E-38,3.402823E+38}},{{1.175494E-38,3.402823E+38},{1.175494E-38,3.402823E+38}}};
static float * arr_ptr_arr_arr_float[2]  = {arr_arr_float[0],arr_arr_float[1]};
static float (* ptr_arr_float)[2]  = &arr_float;
// array of double
static double arr_double[2]  = {2.225074E-308,1.797693E+308};
static double arr_arr_double[2][2]  = {{2.225074E-308,1.797693E+308},{2.225074E-308,1.797693E+308}};
static double arr_arr_arr_double[2][2][2]  = {{{2.225074E-308,1.797693E+308},{2.225074E-308,1.797693E+308}},{{2.225074E-308,1.797693E+308},{2.225074E-308,1.797693E+308}}};
static double * arr_ptr_arr_arr_double[2]  = {arr_arr_double[0],arr_arr_double[1]};
static double (* ptr_arr_double)[2]  = &arr_double;

static int one = 1, two = 2, three = 3, four = 4;
static struct {
  int int_var;
} arr_struct[2]  = {{1},{2}};
static union {
  int int_var;
  float float_var;
} arr_union[2]  = {{1},{2}};
static struct {
  int int_var;
} arr_arr_struct[2][2]  = {{{1},{2}},{{3},{4}}};
static union {
  int int_var;
  float float_var;
} arr_arr_union[2][2]  = {{{1},{2}},{{3},{4}}};
static int * arr_arr_ptr[2][2]  = {{&one,&two},{&three,&four}};
static struct {
  int arr_int[2];
} arr_struct_arr_int[2]  = {{{1, 2}}, {{3, 4}}};
static struct {
  struct {
    int int_var;
  } struct_a;
} arr_struct_struct[2]  = {{{1}},{{2}}};
static struct {
  union {
    int int_var;
    float float_var;
  } struct_a;
} arr_struct_union[2]  = {{{1}},{{2}}};
static struct {
  int * ptr;
} arr_struct_ptr[2]  = {{&one},{&two}};
static union {
  int arr_int[2];
  float arr_float[2];
} arr_union_arr_int[2]  = {{{1, 2}}, {{3, 4}}};
static union {
  struct {
    int int_var;
  } struct_a;
} arr_union_struct[2]  = {{{1}}, {{2}}};
static union {
  union {
    int int_var;
  } union_a;
} arr_union_union[2]  = {{{1}}, {{2}}};
static union {
  int * ptr;
} arr_union_ptr[2]  = {{&one}, {&two}};
static struct {
  int int_var;
} * arr_ptr_struct[2] ;
static union {
  int int_var;
  float float_var;
} * arr_ptr_union[2] ;
static int * * arr_ptr_ptr[2] ;
static struct {
  int int_var;
} (* ptr_arr_struct)[2] ;
static union {
  int int_var;
} (* ptr_arr_union)[2] ;
static int * (* ptr_arr_ptr)[2] ;
typedef struct {
    char char_var;
    short short_var;
    int int_var;
    long long_var;
    float float_var;
    double double_var;
    char arr_char[4];
} type_struct;
typedef struct {
    type_struct type_struct_min;
    type_struct type_struct_max;
} type_type_struct;
type_type_struct type_minmax_struct =
  {{41, -32767-1, -2147483647-1, -2147483647L-1, 1.175494E-38, 2.225074E-308, "ABC"},
   {176, 32767, 2147483647, 2147483647L, 3.402823E+38, 1.797693E+308, "XYZ"}
};
static struct {
  unsigned int bit1_0:1;
  unsigned int bit1_1:1;
  char char_2;
  unsigned int bit1_6:1;
  unsigned int bit1_7:1;
  char char_8;
  unsigned int bit1_9:1;
  unsigned int bit1_10:1;
} bitfields_small_var  = {1, 0, 0x7f, 1, 0, 0x7f, 1, 0};
static struct {
  unsigned char char_0;
  int bit1_4:1;
  unsigned int bit1_5:1;
  int bit2_6:2;
  unsigned int bit2_8:2;
  int bit3_10:3;
  unsigned int bit3_13:3;
  int bit9_16:9;
  unsigned int bit9_25:9;
  char char_34;
} bitfields_bit_var  = {0x7f, 1, 1, 1, 3, 3, 7, UINT8_MAX, 511, 0x7f};
static struct {
  short int arr_short[2];
} struct_arr_short_var  = {{1, 2}};
static struct {
  struct {
    int int_var;
  } struct_a;
} struct_struct_var  = {{1}};
static struct {
  union {
    int int_var;
  } union_a;
} struct_union_var  = {{1}};
static struct {
  int * ptr_int;
} struct_ptr_var  = {&one};
static union {
  int arr_int[4];
  float arr_float[4];
} union_arr_var  = {{1, 2, 3, 4}};
static union {
  struct {
    int int_var;
  } struct_a;
} union_struct_var  = {{1}};
static union {
  union {
    int int_var;
    float float_var;
  } union_a;
} union_union_var  = {{1}};
static union {
  int * ptr_int;
} union_ptr_var  = {&one};
static struct {
  int int_var;
} * ptr_struct_var ;
static union {
  int int_var;
} * ptr_union_var ;
static struct {
  int arr_arr_int[2][2];
} struct_arr_arr_int_var  = {{{1, 2}, {3, 4}}};
static struct {
  struct {
  int int_var;
} arr_struct[2];
} struct_arr_struct_var  = {{{1}, {2}}};
static struct {
  union {
  int int_var;
} arr_union[4];
} struct_arr_union_var  = {{{1}, {2}}};
static struct {
  int * arr_ptr[2];
} struct_arr_ptr_var  = {{&one, &two}};
static struct {
  struct {
    int arr_int[2];
  } struct_arr;
} struct_struct_arr_int_var  = {{{1, 2}}};
static struct {
  struct {
    struct {
      int int_var;
    } struct_a;
  } struct_struct;
} struct_struct_struct_var  = {{{1}}};
static struct {
  struct {
    union {
      char int_var;
    } union_a;
  } struct_union;
} struct_struct_union_var  = {{{1}}};
static struct {
  struct {
    int * ptr_int;
  } sp;
} struct_struct_ptr_var  = {{&three}};
static struct {
  union {
    int arr_int[4];
  } union_arr_int;
} struct_union_arr_var  = {{{1, 2, 3, 4}}};
static struct {
  union {
    struct {
      int int_var;
    } struct_a;
  } union_struct;
} struct_union_struct_var  = {{{1}}};
static struct {
  union {
    union {
      long int int_var;
      float float_var;
    } union_a;
  } union_union;
} struct_union_union_var  = {{{1.0}}};
static struct {
  union {
    int * ptr_int;
  } union_ptr;
} struct_union_ptr_var  = {{&four}};
static struct {
  int (* ptr_arr)[4];
} struct_ptr_arr_var ;
static struct {
  struct {
  int int_var;
} * ptr_struct;
} struct_ptr_struct_var ;
static struct {
  union {
  int int_var;
} * ptr_union;
} struct_ptr_union_var ;
static struct {
  int * * ptr_ptr;
} struct_ptr_ptr_var ;
static union {
  int arr_int[2][2];
  float arr_float[2][2];
} union_arr_int_var  = {{{1, 2}, {3, 4}}};
static union {
  struct {
  int int_var;
} arr_struct[2];
} union_arr_struct_var  = {{{1}}};
static union {
  union {
  int int_var;
  float float_var;
} arr_union[2];
} union_arr_union_var  = {{{1.1}}};
static union {
  int * arr_ptr[4];
} union_arr_ptr_var  = {{&one}};
static union {
  struct {
    int arr_int[4];
  } struct_arr;
} union_struct_arr_int_var  = {{{1, 2, 3, 4}}};
static union {
  struct {
    struct {
      int int_var;
    } struct_a;
  } struct_b;
} union_struct_struct_var  = {{{1}}};
static union {
  struct {
    union {
      int int_var;
      float float_var;
    } union_a;
  } struct_a;
} union_struct_union_var  = {{{1.1}}};
static union {
  struct {
    int * ptr_int;
  } struct_ptr;
} union_struct_ptr_var  = {{&one}};
static union {
  union {
    long long int arr_int[4];
  } union_arr;
} union_union_arr_int_var  = {{{1, 2, 3, 4}}};
static union {
  union {
    struct {
      long long int int_var;
    } struct_a;
  } union_a;
} union_union_struct_var  = {{{1}}};
static union {
  union {
    union {
      int int_var;
      float float_var;
    } union_a;
  } union_b;
} union_union_union_var  = {{{1.1}}};
static union {
  union {
    int * ptr_int;
    float * ptr_float;
  } union_ptr;
} union_union_ptr_var  = {{&one}};
static union {
  int (* ptr_arr)[4];
} union_ptr_arr_var ;
static union {
  struct {
  int int_var;
} * ptr_struct;
} union_ptr_struct_var ;
static union {
  union {
  int int_var;
} * ptr_union;
} union_ptr_union_var ;
static union {
  int * * ptr_ptr;
} union_ptr_ptr_var ;
static struct {
  int arr_int[4];
} * ptr_struct_arr_int_var ;
static struct {
  struct {
    int int_var;
  } struct_a;
} * ptr_struct_struct_var ;
static struct {
  union {
    int int_var;
  } union_a;
} * ptr_struct_union_var ;
static struct {
  int * ptr_int;
} * ptr_struct_ptr_var ;
static union {
  int arr_int[4];
} * ptr_union_arr_int_var ;
static union {
  struct {
    int int_var;
  } struct_a;
} * ptr_union_struct_var ;
static union {
  union {
    int int_var;
  } union_a;
} * ptr_union_union_var ;
static union {
  int * ptr_int;
} * ptr_union_ptr_var ;
static struct {
  int int_var;
} * * ptr_ptr_struct_var ;
static union {
  int int_var;
} * * ptr_ptr_union_var ;
static enum  {
  red = 0,
  green = 1,
  blue = 2
} primary_colors_var ;
static enum colors {
  orange = 0,
  yellow = 1,
  violet = 2,
  indigo = 3
} rainbow_colors_var ;
static enum  {
  chevy = 33,
  dodge = 44,
  ford = 55
} usa_cars_var ;
static enum cars {
  bmw = 0,
  mercedes = 1,
  porsche = 2
} european_cars_var ;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: generating type tests
  2007-10-16 19:47       ` Stan Cox
@ 2007-10-17 11:12         ` Stan Cox
  0 siblings, 0 replies; 9+ messages in thread
From: Stan Cox @ 2007-10-17 11:12 UTC (permalink / raw)
  To: Frysk List

Forgot to mention that I also "split" the original into two scripts:
1. Convert the "builtin" into:
Dcl: struct foo { int i; } f
Name: f
Initial: { 1 }
Type: struct foo { int i; }

2. Build test.c and Test.java (pretend names) from 1.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: generating type tests
  2007-10-15 16:56 ` Andrew Cagney
  2007-10-15 19:13   ` Stan Cox
@ 2007-10-18 16:16   ` Stan Cox
  1 sibling, 0 replies; 9+ messages in thread
From: Stan Cox @ 2007-10-18 16:16 UTC (permalink / raw)
  To: Frysk List

I think this reworking implements the contract we discussed in the
meeting.  gen-type-funit-tests.py builds funit-type-expect.c with type
annotations of the form:
// Test: <name to be given to a "suite" (one test in expect parlance)>
// Name: <variable name>
// Value: <initial value of variable>
// Type: <type as specified in a source program>
// EType: <expanded type as if the typedef were expanded>
gen-type-expect-tests.py builds TestTypeEntry*.java from, for example
funit-type-expect.c, using the type annotations.  Multiple files can be
given so types can be specified standalone outside of the
gen-type-funit-tests.py framework.  This will result in
TestTypeEntry*.java having the form:
    public void testScalar () {
        Expect [] expect  = {...}
      ExpectTest expectTest = new ExpectTest("funit-type-entry");
      expectTest.compareEqual(expect, "testScalar ");
    }
    // testArray/testStruct/testEnum, all generated by 
    // gen-type-funit-tests.py
    public void testAlpha () {
        Expect [] expect  = {
            new Expect("char_var","char"),
        }
      ExpectTest expectTest = new ExpectTest("x");
      expectTest.compareEqual(expect, "testScalar ");
    }
testAlpha is generated from x.c via:
gen-type-expect-tests.py -type funit-type-entry.c x.c
from this x.c:
// Test: Alpha
static char char_var = 176;
// Name: char_var
// Value: 176
// Type: char
main (int argc, char **argv)
{}

The "Type" testing passes for those types currently being generated by
gen-type-funit*. Here is a run of TestRunner done with the assistance of
some makefile surgery.
Running testScalar(frysk.debuginfo.TestTypeEntry)
PASS
Running testArray(frysk.debuginfo.TestTypeEntry)
PASS
Running testStruct(frysk.debuginfo.TestTypeEntry)
PASS
Running testEnum(frysk.debuginfo.TestTypeEntry)
PASS

Time: 0.21

OK (4 tests)




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-10-18 16:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-12 21:18 generating type tests Stan Cox
2007-10-12 22:54 ` Andrew Cagney
2007-10-15  2:10   ` Stan Cox
2007-10-15 16:50     ` Andrew Cagney
2007-10-16 19:47       ` Stan Cox
2007-10-17 11:12         ` Stan Cox
2007-10-15 16:56 ` Andrew Cagney
2007-10-15 19:13   ` Stan Cox
2007-10-18 16:16   ` Stan Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).