public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
* Improvements for GAS testcase generation
@ 2001-06-13 18:20 Geoffrey Keating
  2001-06-13 19:56 ` Doug Evans
  2001-06-14  0:28 ` Ben Elliston
  0 siblings, 2 replies; 3+ messages in thread
From: Geoffrey Keating @ 2001-06-13 18:20 UTC (permalink / raw)
  To: cgen

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))
============================================================

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

* Improvements for GAS testcase generation
  2001-06-13 18:20 Improvements for GAS testcase generation Geoffrey Keating
@ 2001-06-13 19:56 ` Doug Evans
  2001-06-14  0:28 ` Ben Elliston
  1 sibling, 0 replies; 3+ messages in thread
From: Doug Evans @ 2001-06-13 19:56 UTC (permalink / raw)
  To: geoffk; +Cc: cgen

Geoffrey Keating writes:
 > 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 old generator was a quick hack to get something going pending
someone to come along and do something better.  [Isn't there something
in ESR's paper about not trying to do everything and leaving some
things for someone else to do? :-)]

 > OK to commit?

Yep, thanks!

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

* Re: Improvements for GAS testcase generation
  2001-06-13 18:20 Improvements for GAS testcase generation Geoffrey Keating
  2001-06-13 19:56 ` Doug Evans
@ 2001-06-14  0:28 ` Ben Elliston
  1 sibling, 0 replies; 3+ messages in thread
From: Ben Elliston @ 2001-06-14  0:28 UTC (permalink / raw)
  To: geoffk; +Cc: cgen

>>>>> "Geoffrey" == Geoffrey Keating <geoffk@cygnus.com> writes:

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

I had a stab at improving this a couple of months ago, but left some
of it undone (those parts you've improved with your patch).  Thanks
for improving it further!

I see Doug has already approved the patch.

Ben

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

end of thread, other threads:[~2001-06-14  0:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-13 18:20 Improvements for GAS testcase generation Geoffrey Keating
2001-06-13 19:56 ` Doug Evans
2001-06-14  0:28 ` Ben Elliston

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).