Skip to content

Commit

Permalink
make test/ken safe for optional semis
Browse files Browse the repository at this point in the history
  • Loading branch information
griesemer committed Dec 10, 2009
1 parent d08d33f commit 581530e
Show file tree
Hide file tree
Showing 32 changed files with 188 additions and 394 deletions.
36 changes: 12 additions & 24 deletions test/ken/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
package main

func
setpd(a []int)
{
setpd(a []int) {
// print("setpd a=", a, " len=", len(a), " cap=", cap(a), "\n");
for i:=0; i<len(a); i++ {
a[i] = i;
}
}

func
sumpd(a []int) int
{
sumpd(a []int) int {
// print("sumpd a=", a, " len=", len(a), " cap=", cap(a), "\n");
t := 0;
for i:=0; i<len(a); i++ {
Expand All @@ -28,17 +26,15 @@ sumpd(a []int) int
}

func
setpf(a *[20]int)
{
setpf(a *[20]int) {
// print("setpf a=", a, " len=", len(a), " cap=", cap(a), "\n");
for i:=0; i<len(a); i++ {
a[i] = i;
}
}

func
sumpf(a *[20]int) int
{
sumpf(a *[20]int) int {
// print("sumpf a=", a, " len=", len(a), " cap=", cap(a), "\n");
t := 0;
for i:=0; i<len(a); i++ {
Expand All @@ -49,8 +45,7 @@ sumpf(a *[20]int) int
}

func
res(t int, lb, hb int)
{
res(t int, lb, hb int) {
sb := (hb-lb)*(hb+lb-1)/2;
if t != sb {
print( "lb=", lb,
Expand All @@ -64,8 +59,7 @@ res(t int, lb, hb int)

// call ptr dynamic with ptr dynamic
func
testpdpd()
{
testpdpd() {
a := make([]int, 10, 100);
if len(a) != 10 && cap(a) != 100 {
panic("len and cap from new: ", len(a), " ", cap(a), "\n");
Expand All @@ -83,8 +77,7 @@ testpdpd()

// call ptr fixed with ptr fixed
func
testpfpf()
{
testpfpf() {
var a [20]int;

setpf(&a);
Expand All @@ -93,8 +86,7 @@ testpfpf()

// call ptr dynamic with ptr fixed from new
func
testpdpf1()
{
testpdpf1() {
a := new([40]int);
setpd(a);
res(sumpd(a), 0, 40);
Expand All @@ -105,8 +97,7 @@ testpdpf1()

// call ptr dynamic with ptr fixed from var
func
testpdpf2()
{
testpdpf2() {
var a [80]int;

setpd(&a);
Expand All @@ -115,8 +106,7 @@ testpdpf2()

// generate bounds error with ptr dynamic
func
testpdfault()
{
testpdfault() {
a := make([]int, 100);

print("good\n");
Expand All @@ -130,8 +120,7 @@ testpdfault()

// generate bounds error with ptr fixed
func
testfdfault()
{
testfdfault() {
var a [80]int;

print("good\n");
Expand All @@ -145,8 +134,7 @@ testfdfault()
}

func
main()
{
main() {
testpdpd();
testpfpf();
testpdpf1();
Expand Down
70 changes: 24 additions & 46 deletions test/ken/chan.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ import "runtime"
var randx int;

func
nrand(n int) int
{
nrand(n int) int {
randx += 10007;
if randx >= 1000000 {
randx -= 1000000;
}
return randx%n;
}

type Chan
struct
{
type Chan struct {
sc,rc chan int; // send and recv chan
sv,rv int; // send and recv seq
}
Expand All @@ -38,14 +35,12 @@ var
)

func
init()
{
init() {
nc = new(Chan);
}

func
mkchan(c,n int) []*Chan
{
mkchan(c,n int) []*Chan {
ca := make([]*Chan, n);
for i:=0; i<n; i++ {
cval = cval+100;
Expand All @@ -60,8 +55,7 @@ mkchan(c,n int) []*Chan
}

func
expect(v, v0 int) (newv int)
{
expect(v, v0 int) (newv int) {
if v == v0 {
if v%100 == 75 {
return end;
Expand All @@ -71,9 +65,7 @@ expect(v, v0 int) (newv int)
panic("got ", v, " expected ", v0+1, "\n");
}

func (c *Chan)
send() bool
{
func (c *Chan) send() bool {
// print("send ", c.sv, "\n");
tots++;
c.sv = expect(c.sv, c.sv);
Expand All @@ -85,8 +77,7 @@ send() bool
}

func
send(c *Chan)
{
send(c *Chan) {
nproc++; // total goroutines running
for {
for r:=nrand(10); r>=0; r-- {
Expand All @@ -100,9 +91,7 @@ send(c *Chan)
nproc--;
}

func (c *Chan)
recv(v int) bool
{
func (c *Chan) recv(v int) bool {
// print("recv ", v, "\n");
totr++;
c.rv = expect(c.rv, v);
Expand All @@ -114,8 +103,7 @@ recv(v int) bool
}

func
recv(c *Chan)
{
recv(c *Chan) {
var v int;

nproc++; // total goroutines running
Expand All @@ -132,8 +120,7 @@ recv(c *Chan)
}

func
sel(r0,r1,r2,r3, s0,s1,s2,s3 *Chan)
{
sel(r0,r1,r2,r3, s0,s1,s2,s3 *Chan) {
var v int;

nproc++; // total goroutines running
Expand Down Expand Up @@ -196,16 +183,14 @@ sel(r0,r1,r2,r3, s0,s1,s2,s3 *Chan)

// direct send to direct recv
func
test1(c *Chan)
{
test1(c *Chan) {
go send(c);
go recv(c);
}

// direct send to select recv
func
test2(c int)
{
test2(c int) {
ca := mkchan(c,4);

go send(ca[0]);
Expand All @@ -218,8 +203,7 @@ test2(c int)

// select send to direct recv
func
test3(c int)
{
test3(c int) {
ca := mkchan(c,4);

go recv(ca[0]);
Expand All @@ -232,26 +216,23 @@ test3(c int)

// select send to select recv
func
test4(c int)
{
test4(c int) {
ca := mkchan(c,4);

go sel(nc,nc,nc,nc, ca[0],ca[1],ca[2],ca[3]);
go sel(ca[0],ca[1],ca[2],ca[3], nc,nc,nc,nc);
}

func
test5(c int)
{
test5(c int) {
ca := mkchan(c,8);

go sel(ca[4],ca[5],ca[6],ca[7], ca[0],ca[1],ca[2],ca[3]);
go sel(ca[0],ca[1],ca[2],ca[3], ca[4],ca[5],ca[6],ca[7]);
}

func
test6(c int)
{
test6(c int) {
ca := mkchan(c,12);

go send(ca[4]);
Expand All @@ -270,8 +251,7 @@ test6(c int)

// wait for outstanding tests to finish
func
wait()
{
wait() {
runtime.Gosched();
for nproc != 0 {
runtime.Gosched();
Expand All @@ -280,8 +260,7 @@ wait()

// run all tests with specified buffer size
func
tests(c int)
{
tests(c int) {
ca := mkchan(c,4);
test1(ca[0]);
test1(ca[1]);
Expand All @@ -307,19 +286,18 @@ tests(c int)

// run all test with 4 buffser sizes
func
main()
{
main() {

tests(0);
tests(1);
tests(10);
tests(100);

t := 4 // buffer sizes
* ( 4*4 // tests 1,2,3,4 channels
+ 8 // test 5 channels
+ 12 // test 6 channels
) * 76; // sends/recvs on a channel
t := 4 * // buffer sizes
( 4*4 + // tests 1,2,3,4 channels
8 + // test 5 channels
12 ) * // test 6 channels
76; // sends/recvs on a channel

if tots != t || totr != t {
print("tots=", tots, " totr=", totr, " sb=", t, "\n");
Expand Down
11 changes: 4 additions & 7 deletions test/ken/chan1.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ const W = 2; // channel buffering
var h [N]int; // marking of send/recv

func
r(c chan int, m int)
{
r(c chan int, m int) {
for {
select {
case r := <- c:
if h[r] != 1 {
panicln("r",
"m=", m,
"r=", r,
"h=", h[r]
"h=", h[r],
);
}
h[r] = 2;
Expand All @@ -32,8 +31,7 @@ r(c chan int, m int)
}

func
s(c chan int)
{
s(c chan int) {
for n:=0; n<N; n++ {
r := n;
if h[r] != 0 {
Expand All @@ -45,8 +43,7 @@ s(c chan int)
}

func
main()
{
main() {
c := make(chan int, W);
for m:=0; m<M; m++ {
go r(c, m);
Expand Down
9 changes: 3 additions & 6 deletions test/ken/complit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ type SC struct{ a,b,c []int };
type SM struct{ a,b,c M };

func
main()
{
main() {
test("s.a", s.a);
test("s.b", s.b);
test("s.c", s.c);
Expand Down Expand Up @@ -79,8 +78,7 @@ main()
var ref = 0;

func
test(xs string, x int)
{
test(xs string, x int) {

if ref >= len(answers) {
println(xs, x);
Expand Down Expand Up @@ -119,8 +117,7 @@ var ms = map[int]S{0:S{5101,5102,5103},1:S{5104,5105,5106},2:S{5107,5108,5109}}
var mc = map[int][]int{0:[]int{5201,5202,5203}, 1:[]int{5204,5205,5206}, 2:[]int{5207,5208,5209}}
var mm = map[int]M{0:M{0:5301,1:5302,2:5303}, 1:M{0:5304,1:5305,2:5306}, 2:M{0:5307,1:5308,2:5309}}

var answers = [...]int
{
var answers = [...]int {
// s
1101, 1102, 1103,

Expand Down
Loading

0 comments on commit 581530e

Please sign in to comment.