This is the mail archive of the cgen@sources.redhat.com mailing list for the CGEN project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Improvements for GAS testcase generation



This patch changes the GAS testcase generator.  The old generator used
to pick a few random small integers or a random keyword as operands.
The new generator tries to find values that actually fit in the
fields, and uses some bit patterns which make it easier to verify that
the testcase is correct.

The patch was necessary for a Red Hat confidential port.  The part had
some instructions which had a field width for a register operand that
couldn't actually specify all the registers; the extra registers were
just not allowed for that operand.

OK to commit?

-- 
Geoff Keating <geoffk@redhat.com>

===File ~/patches/cgen-gastestfields.patch==================
2001-06-13  Geoffrey Keating  <geoffk@redhat.com>

	* gas-test.scm (gen-gas-test): Create 8 testcases, not just 5.
	(<operand> 'test-data): Involve both the index and the hardware
	in testcase generation.
	(<hw-indx> 'test-data): Generate test data from the underlying
	object.
	(<ifield> 'test-data): Generate test data by computing bit
	patterns for the field, then decoding them.
	(<hw-address> 'test-data): Allow for new calling convention.
	(<hw-iaddress> 'test-data): Likewise.
	(<keyword> 'test-data): Convert index values into keywords.
	(<hw-asm> 'test-data): Convert index values into integer strings.

Index: devo/cgen/gas-test.scm
===================================================================
RCS file: /cvs/cvsfiles/devo/cgen/gas-test.scm,v
retrieving revision 1.30
diff -p -u -p -r1.30 gas-test.scm
--- gas-test.scm	2001/05/11 02:20:21	1.30
+++ gas-test.scm	2001/06/14 00:57:04
@@ -29,59 +29,94 @@
 ; The result is a list of strings to be inserted in the assembler
 ; in the operand's position.
 
+; For a general assembler operand, just turn the value into a string.
 (method-make!
  <hw-asm> 'test-data
- (lambda (self n)
-   ; FIXME: floating point support
-   (let* ((signed (list 0 1 -1 2 -2))
-	  (unsigned (list 0 1 2 3 4))
-	  (mode (elm-get self 'mode))
-	  (test-cases (if (eq? (mode:class mode) 'UINT) unsigned signed))
-	  (selection (map (lambda (z) (random (length test-cases))) (iota n))))
-     ; FIXME: wider ranges.
-     (map number->string
-	  (map (lambda (n) (list-ref test-cases n)) selection))))
+ (lambda (self ops)
+   (map number->string ops))
 )
 
+; For a keyword operand, choose the appropriate keyword.
 (method-make!
  <keyword> 'test-data
- (lambda (self n)
+ (lambda (self ops)
    (let* ((test-cases (elm-get self 'values))
-	  (selection (map (lambda (z) (random (length test-cases))) (iota n)))
 	  (prefix (elm-get self 'prefix)))
      (map (lambda (n)
-	    (string-append 
-	     (if (eq? (string-ref prefix 0) #\$) "\\" "")
-	     (elm-get self 'prefix) (car (list-ref test-cases n))))
-	  selection)))
+ 	    (string-append 
+ 	     (if (and (not (string=? prefix ""))
+		      (eq? (string-ref prefix 0) #\$))
+		 "\\" "")
+ 	     prefix 
+	     (car (list-ref test-cases n))))
+ 	  ops)))
 )
 
 (method-make!
  <hw-address> 'test-data
- (lambda (self n)
+ (lambda (self ops)
    (let* ((test-cases '("foodata" "4" "footext" "-4"))
+	  (n (length ops))
 	  (selection (map (lambda (z) (random (length test-cases))) (iota n))))
      (map (lambda (n) (list-ref test-cases n)) selection)))
 )
 
 (method-make!
  <hw-iaddress> 'test-data
- (lambda (self n)
+ (lambda (self ops)
    (let* ((test-cases '("footext" "4" "foodata" "-4"))
+	  (n (length ops))
 	  (selection (map (lambda (z) (random (length test-cases))) (iota n))))
      (map (lambda (n) (list-ref test-cases n)) selection)))
 )
 
 (method-make-forward! <hw-register> 'indices '(test-data))
 (method-make-forward! <hw-immediate> 'values '(test-data))
+
+; Test data for a field is chosen firstly out of some bit patterns,
+; then randomly.  It is then interpreted based on whether there 
+; is a decode method.
+(method-make!
+ <ifield> 'test-data
+ (lambda (self n)
+   (let* ((bf-len (ifld-length self))
+	  (field-max (inexact->exact (round (expt 2 bf-len))))
+	  (highbit (quotient field-max 2))
+	  (values (map (lambda (n) 
+			 (case n
+			   ((0) 0)
+			   ((1) (- field-max 1))
+			   ((2) highbit)
+			   ((3) (- highbit 1))
+			   ((4) 1)
+			   (else (random field-max))))
+		       (iota n)))
+	  (decode (ifld-decode self)))
+     (if decode
+	 ; FIXME: need to run the decoder.
+	 values
+	 ; no decode method
+	 (case (mode:class (ifld-mode self))
+	   ((INT) (map (lambda (n) (if (>= n highbit) (- n field-max) n)) 
+		       values))
+	   ((UINT) values)
+	   (else (error "unsupported mode class" 
+			(mode:class (ifld-mode self))))))))
+)
 
-; This can't use method-make-forward! as we need to call op:type to
-; resolve the hardware reference.
+(method-make!
+ <hw-index> 'test-data
+ (lambda (self n)
+   (case (hw-index:type self)
+     ((ifield operand) (send (hw-index:value self) 'test-data n))
+     ((constant) (hw-index:value self))
+     (else nil)))
+)
 
 (method-make!
  <operand> 'test-data
  (lambda (self n)
-   (send (op:type self) 'test-data n))
+   (send (op:type self) 'test-data (send (op:index self) 'test-data n)))
 )
 
 ; Given an operand, return a set of N test data.
@@ -152,7 +187,7 @@
    (gen-sym insn) ":\n"
    (let* ((syntax-list (insn-tmp insn))
 	  (op-list (extract-operands syntax-list))
-	  (test-set (build-test-set op-list 5)))
+	  (test-set (build-test-set op-list 8)))
      (string-map (lambda (test-data)
 		   (build-asm-testcase syntax-list test-data))
 		 test-set))
============================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]