# HG changeset patch # User Francisco J Ballesteros # Date 1328893950 0 # Node ID 6301c34f4f81c573c52ceecef0d63b0681501ba1 # Parent fb5824366f81c8551b375f7c8cebd392718ed1df regression: tests added R=nixiedev, john CC=nix-dev http://codereview.appspot.com/5536050 diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/1/kern --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/nix/test/1/kern Fri Feb 10 17:12:30 2012 +0000 @@ -0,0 +1,19 @@ +#!/bin/rc + +rfork ne + +# import rc functions popular among scripts, e.g. fail +# +. ../tools + +# we might have a main.c file here and do something like: +# bind main.c ../../k10/main.c +# to override the source used for this test + +# we might change the std source like this: +# sed 's/initialTCs = [0-9]+/initialTCs = 16/' < ../../k10/main.c >main.c +# bind main.c ../../k10/main.c + +cd /sys/src/nix/k10 +mk clean +mk install diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/1/koutput --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/nix/test/1/koutput Fri Feb 10 17:12:30 2012 +0000 @@ -0,0 +1,193 @@ +rm -f *.[5678qv] *.root.[cs] *.out *.m *.acid errstr.h init.h amd64^l.h +for(i in k8cpu) + mk $i.clean +@{cd ../root; mk clean} +if(test -d ./root) @{cd ./root; mk clean}; status='' +rm -f k8cpu.c [9bz]k8cpu [9bz]k8cpu.gz bootk8cpu.* +rm -f *.[5678qv] *.a[5678qv] y.tab.? lex.yy.c y.debug y.output [5678qv].??* big bigloop blow cpu suck $CLEANFILES +rm -f *.[5678qv] *.a[5678qv] y.tab.? lex.yy.c y.debug y.output [5678qv].??* cpu $CLEANFILES +awk -f ../mk/parse -- -mkdevc k8cpu > k8cpu.c +rc ../mk/mkenum amd64.h > amd64l.h +6a $AFLAGS l64cpuid.s +6a $AFLAGS l64fpu.s +6c -FTVw -I. -D'_DBGC_=''c''' ./acore.c +6c -FTVw -I. -D'_DBGC_=''V''' ./arch.c +6c -FTVw archk10.c +6c -FTVw -I. -D'_DBGC_=''m''' ./asm.c +6c -FTVw cga.c +6c -FTVw crap.c +6c -FTVw fpu.c +6c -FTVw i8254.c +6c -FTVw i8259.c +6c -FTVw -I. ../386/kbd.c +6c -FTVw init9.c +6c -FTVw -I. ../port/initcode.c +6c -FTVw map.c +6c -FTVw -I. -D'_DBGC_=''m''' ./memory.c +6c -FTVw -I. -D'_DBGC_=''v''' ./mmu.c +6c -FTVw multiboot.c +6c -FTVw qmalloc.c +6c -FTVw -I. ../386/random.c +6c -FTVw syscall.c +6c -FTVw -I. -D'_DBGC_=''c''' ./tcore.c +6c -FTVw trap.c +6c -FTVw vsvm.c +6c -FTVw -I. -D'_DBGC_=''m''' ./physalloc.c +6c -FTVw -I. ../port/print.c +6c -I../boot -FTVw ../boot/bootauth.c +6c -I../boot -FTVw ../boot/aux.c +6c -I../boot -FTVw ../boot/boot.c +6c -I../boot -FTVw ../boot/bootcache.c +6c -I../boot -FTVw ../boot/bootip.c +6c -I../boot -FTVw ../boot/local.c +6c -I../boot -FTVw ../boot/embed.c +6c -I../boot -FTVw ../boot/settime.c +6c -I../boot -FTVw ../boot/sac.c +6c -I../boot -FTVw ../boot/paq.c +6c -I../boot -FTVw ../boot/printstub.c +6c -FTVw -I. ../386/ether8169.c +6c -FTVw -I. ../386/devrtc.c +6c -FTVw -I. ../port/netif.c +6c -FTVw -I. ../port/devssl.c +6c -FTVw -I. ../ip/ip.c +6c -FTVw -I. ../ip/ipv6.c +6c -FTVw -I. ../386/pci.c +6c -FTVw ether82563.c +6c -FTVw -I. ../ip/devip.c +6c -FTVw -I. ../port/devuart.c +6c -FTVw -I. ../port/ethermii.c +6c -FTVw -I. ../386/etherigbe.c +6c -FTVw -I. ../port/devproc.c +6c -FTVw -I. ../port/devkprof.c +6c -FTVw -I. ../ip/netlog.c +6c -FTVw -I. ../ip/nullmedium.c +6c -FTVw -I. ../386/ether82557.c +6c -FTVw -I. ../ip/tcp.c +6c -FTVw -I. -D'_DBGC_=''I''' ./ioapic.c +6c -FTVw -I. ../port/devsrv.c +6c -FTVw -I. ../ip/ipaux.c +6c -FTVw -I. ../port/devenv.c +6c -FTVw -I. ../port/devdup.c +6c -FTVw -I. ../port/devpipe.c +6c -FTVw -I. ../ip/arp.c +6c -FTVw -I. ../386/uartpci.c +6c -FTVw -I. -D'_DBGC_=''M''' ./mp.c +6c -FTVw -I. -D'_DBGC_=''T''' ../port/devtube.c +6c -FTVw pmcio.c +6c -FTVw -I. -D'_DBGC_=''z''' ../port/devsegment.c +6c -FTVw -I. ../ip/icmp.c +6c -FTVw -I. ../ip/icmp6.c +6c -FTVw -I. ../ip/ptclbsum.c +6c -FTVw -I. ../ip/ethermedium.c +6c -FTVw -I. ../ip/ipifc.c +6c -FTVw -I. ../386/devether.c +6c -FTVw -I. ../386/uarti8250.c +6c -FTVw -I. ../ip/iproute.c +6c -FTVw devarch.c +6c -FTVw -I. ../ip/inferno.c +6c -FTVw -I. ../port/devmnt.c +6c -FTVw -I. -D'_DBGC_=''C''' ./devacpi.c +6c -FTVw -I. ../ip/chandial.c +6c -FTVw -I. ../ip/netdevmedium.c +6c -FTVw -I. -D'_DBGC_=''A''' ./apic.c +warning: ../port/devtube.c:135 empty if body +warning: ../port/devtube.c:137 empty if body +6c -FTVw -I. ../port/devcap.c +6c -FTVw -I. ../port/devws.c +6c -FTVw -I. ../ip/loopbackmedium.c +6c -FTVw -I. ../port/devcons.c +6c -FTVw -I. ../ip/pktmedium.c +6c -FTVw -I. ../ip/udp.c +6c -FTVw -I. -D'_DBGC_=''z''' ../port/devzp.c +6c -FTVw -I. ../port/devroot.c +6c -FTVw -I. ../port/devpmc.c +6c -FTVw -I. ../port/tod.c +6c -FTVw -I. ../port/sysauth.c +6c -FTVw -I. -D'_DBGC_=''p''' ../port/pager.c +6c -FTVw -I. ../port/edf.c +6c -FTVw -I. ../port/latin1.c +6c -FTVw -I. -D'_DBGC_=''z''' ../port/syszio.c +6c -FTVw -I. ../port/segment.c +6c -FTVw -I. ../port/allocb.c +6c -FTVw -I. -D'_DBGC_=''n''' ../port/nixcall.c +6c -FTVw -I. ../port/systab.c +6c -FTVw -I. ../port/qio.c +awk -f ../mk/parse -- -mkerrstr > errstr.h +6c -FTVw -I. ../port/ps.c +6c -FTVw -I. ../port/fault.c +6c -FTVw -I. -D'_DBGC_=''p''' ../port/image.c +6c -FTVw -I. -D'_DBGC_=''p''' ../port/page.c +6c -FTVw -I. -D'_DBGC_=''p''' ../port/sysseg.c +6c -FTVw -I. ../port/parse.c +6c -FTVw -I. ../port/devtab.c +6c -FTVw -I. -D'_DBGC_=''S''' ../port/syssem.c +6c -FTVw -I. ../port/dev.c +6c -FTVw -I. ../port/rebootcmd.c +6c -FTVw -I. -D'_DBGC_=''E''' ../port/sysproc.c +6c -FTVw -I. ../port/portclock.c +6c -FTVw -I. ../port/chan.c +6c -FTVw -I. ../port/syscallfmt.c +6c -FTVw -I. ../port/pgrp.c +6c -FTVw -I. ../port/qlock.c +6c -FTVw -I. ../port/alarm.c +6c -FTVw -I. ../port/sysfile.c +6c -FTVw -I. ../port/taslock.c +6a $AFLAGS l32p.s +6a $AFLAGS l64v.s +6a $AFLAGS l64idt.s +6a $AFLAGS l64acidt.s +6a $AFLAGS l64syscall.s +6a $AFLAGS l64acsyscall.s +6a $AFLAGS l64sipi.s +6l -l -R1 -s -o init.out init9.6 initcode.6 -lc +6c -FTVw -I. ../port/proc.c +6l -o l64sipi.out -T0xfffffffff0003000 -R4 -l -s l64sipi.6 +{echo 'uchar sipihandler[]={' + xd -1x l64sipi.out | + sed -e 's/^[0-9a-f]+ //' \ + -e '1,2d' -e '3s/^ .. .. .. .. .. .. .. ..//' \ + -e 's/ ([0-9a-f][0-9a-f])/0x\1,/g' + echo '};'} > sipi.h +{echo 'uchar initcode[]={' + xd -1x init.out | sed -e 's/^[0-9a-f]+ //' -e 's/ ([0-9a-f][0-9a-f])/0x\1,/g' + echo '};'} > init.h +names=`{membername $newprereq} +ar vu ../boot/libboot.a6 $names +rm $names +6c -FTVw sipi.c +6c -FTVw -I. -D'_DBGC_=''x''' ./main.c +r - bootauth.6 +r - aux.6 +r - boot.6 +r - bootcache.6 +r - bootip.6 +r - local.6 +r - embed.6 +r - settime.6 +r - sac.6 +r - paq.6 +r - printstub.6 +awk -f ../mk/parse -- -mkbootconf k8cpu > bootk8cpu.c +6c -FTVw bootk8cpu.c +6c -FTVw ../boot/printstub.c +6l -o bootk8cpu.out bootk8cpu.6 ../boot/libboot.a6 printstub.6 +../mk/mkrootall\ + boot bootk8cpu_out bootk8cpu.out\ + factotum _amd64_bin_auth_factotum /amd64/bin/auth/factotum\ + ipconfig _amd64_bin_ip_ipconfig /amd64/bin/ip/ipconfig\ + nvram ___root_nvram ../root/nvram\ +>k8cpu.root.s +6a $AFLAGS k8cpu.root.s +6c -FTVw '-DKERNDATE='`{date -n} k8cpu.c +6l -o 9k8cpu -T0xfffffffff0110000 -R4096 -l l32p.6 l64v.6 l64idt.6 l64acidt.6 l64cpuid.6 l64syscall.6 l64acsyscall.6 l64fpu.6 acore.6 arch.6 archk10.6 asm.6 cga.6 crap.6 fpu.6 i8254.6 i8259.6 kbd.6 main.6 map.6 memory.6 mmu.6 multiboot.6 qmalloc.6 random.6 syscall.6 tcore.6 trap.6 vsvm.6 physalloc.6 k8cpu.root.6 ether8169.6 devrtc.6 netif.6 devssl.6 ip.6 ipv6.6 pci.6 ether82563.6 devip.6 devuart.6 ethermii.6 etherigbe.6 devproc.6 devkprof.6 netlog.6 nullmedium.6 ether82557.6 tcp.6 ioapic.6 devsrv.6 ipaux.6 devenv.6 devdup.6 devpipe.6 arp.6 uartpci.6 mp.6 devtube.6 pmcio.6 devsegment.6 icmp.6 sipi.6 icmp6.6 ptclbsum.6 ethermedium.6 ipifc.6 devether.6 uarti8250.6 iproute.6 devarch.6 inferno.6 devmnt.6 devacpi.6 chandial.6 netdevmedium.6 apic.6 devcap.6 devws.6 loopbackmedium.6 devcons.6 pktmedium.6 udp.6 devzp.6 devroot.6 devpmc.6 tod.6 sysauth.6 pager.6 edf.6 latin1.6 syszio.6 segment.6 allocb.6 nixcall.6 systab.6 qio.6 proc.6 ps.6 fault.6 image.6 page.6 sysseg.6 parse.6 devtab.6 syssem.6 dev.6 rebootcmd.6 sysproc.6 portclock.6 chan.6 syscallfmt.6 pgrp.6 qlock.6 alarm.6 print.6 sysfile.6 taslock.6 k8cpu.6 /amd64/lib/libip.a /amd64/lib/libc.a /amd64/lib/libsec.a +6l -o 9k8cpu.elf -H5 -8 -T0xfffffffff0110000 -l l32p.6 l64v.6 l64idt.6 l64acidt.6 l64cpuid.6 l64syscall.6 l64acsyscall.6 l64fpu.6 acore.6 arch.6 archk10.6 asm.6 cga.6 crap.6 fpu.6 i8254.6 i8259.6 kbd.6 main.6 map.6 memory.6 mmu.6 multiboot.6 qmalloc.6 random.6 syscall.6 tcore.6 trap.6 vsvm.6 physalloc.6 k8cpu.root.6 ether8169.6 devrtc.6 netif.6 devssl.6 ip.6 ipv6.6 pci.6 ether82563.6 devip.6 devuart.6 ethermii.6 etherigbe.6 devproc.6 devkprof.6 netlog.6 nullmedium.6 ether82557.6 tcp.6 ioapic.6 devsrv.6 ipaux.6 devenv.6 devdup.6 devpipe.6 arp.6 uartpci.6 mp.6 devtube.6 pmcio.6 devsegment.6 icmp.6 sipi.6 icmp6.6 ptclbsum.6 ethermedium.6 ipifc.6 devether.6 uarti8250.6 iproute.6 devarch.6 inferno.6 devmnt.6 devacpi.6 chandial.6 netdevmedium.6 apic.6 devcap.6 devws.6 loopbackmedium.6 devcons.6 pktmedium.6 udp.6 devzp.6 devroot.6 devpmc.6 tod.6 sysauth.6 pager.6 edf.6 latin1.6 syszio.6 segment.6 allocb.6 nixcall.6 systab.6 qio.6 proc.6 ps.6 fault.6 image.6 page.6 sysseg.6 parse.6 devtab.6 syssem.6 dev.6 rebootcmd.6 sysproc.6 portclock.6 chan.6 syscallfmt.6 pgrp.6 qlock.6 alarm.6 print.6 sysfile.6 taslock.6 k8cpu.6 /amd64/lib/libip.a /amd64/lib/libc.a /amd64/lib/libsec.a +size 9k8cpu +560858t + 560160d + 192416b = 1313434 9k8cpu +strip -o /fd/1 9k8cpu | gzip -9 > 9k8cpu.gz +--r-xrwxr-x M 9 nemo sys 1410811 Jan 18 11:26 /amd64/9k8cpu +--r--rw-r-- M 9 nemo sys 461939 Jan 18 11:26 /amd64/9k8cpu.gz +--rwxrwxr-x M 13 nemo sys 1410811 Jan 18 11:26 /n/9/amd64/9k8cpu +--rw-rw-r-- M 13 nemo sys 461939 Jan 18 11:26 /n/9/amd64/9k8cpu.gz +--r-xrwxr-x M 15 esoriano sys 1410811 Jan 18 11:26 /n/planb/amd64/9k8cpu +--r--rw-r-- M 15 rminnich sys 461939 Jan 18 11:26 /n/planb/amd64/9k8cpu.gz +done diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/1/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/nix/test/1/main.c Fri Feb 10 17:12:30 2012 +0000 @@ -0,0 +1,571 @@ +#include "u.h" +#include "../port/lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" + +#include "init.h" +#include "io.h" + +static int initialTCs = 16;; /* default # of TCs */ + +Conf conf; /* XXX - must go - gag */ + +extern void crapoptions(void); /* XXX - must go */ +extern void confsetenv(void); /* XXX - must go */ + +static uintptr sp; /* XXX - must go - user stack of init proc */ + +uintptr kseg0 = KZERO; +Sys* sys = nil; +usize sizeofSys = sizeof(Sys); + +/* + * Option arguments from the command line. + * oargv[0] is the boot file. + * Optionsinit() is called from multiboot() to + * set it all up. + */ +static int oargc; +static char* oargv[20]; +static char oargb[128]; +static int oargblen; + +static int maxcores = 1024; /* max # of cores given as an argument */ + +char dbgflg[256]; +static int vflag = 0; + +void +optionsinit(char* s) +{ + oargblen = strecpy(oargb, oargb+sizeof(oargb), s) - oargb; + oargc = tokenize(oargb, oargv, nelem(oargv)-1); + oargv[oargc] = nil; +} + +static void +options(int argc, char* argv[]) +{ + char *p; + int n, o; + + /* + * Process flags. + * Flags [A-Za-z] may be optionally followed by + * an integer level between 1 and 127 inclusive + * (no space between flag and level). + * '--' ends flag processing. + */ + while(--argc > 0 && (*++argv)[0] == '-' && (*argv)[1] != '-'){ + while(o = *++argv[0]){ + if(!(o >= 'A' && o <= 'Z') && !(o >= 'a' && o <= 'z')) + continue; + n = strtol(argv[0]+1, &p, 0); + if(p == argv[0]+1 || n < 1 || n > 127) + n = 1; + argv[0] = p-1; + dbgflg[o] = n; + } + } + vflag = dbgflg['v']; + if(argc > 0){ + maxcores = strtol(argv[0], 0, 0); + argc--; + argv++; + } + if(argc > 0){ + initialTCs = strtol(argv[0], 0, 0); + //argc--; + //argv++; + } +} + +extern void setmachsched(Mach*); + +void +squidboy(int apicno) +{ + char *n[] = { + [NIXAC] "AC", + [NIXTC] "TC", + [NIXKC] "KC" + }; + vlong hz; + + sys->machptr[m->machno] = m; + setmachsched(m); + /* + * Need something for initial delays + * until a timebase is worked out. + */ + m->cpuhz = 2000000000ll; + m->cpumhz = 2000; + m->perf.period = 1; + + m->nixtype = NIXAC; + + DBG("Hello Squidboy %d %d\n", apicno, m->machno); + + vsvminit(MACHSTKSZ, m->nixtype); + + /* + * Beware the Curse of The Non-Interruptable Were-Temporary. + */ + hz = archhz(); + if(hz == 0) + ndnr(); + m->cpuhz = hz; + m->cyclefreq = hz; + m->cpumhz = hz/1000000ll; + + mmuinit(); + if(!apiconline()) + ndnr(); + fpuinit(); + + acmodeset(m->nixtype); + m->splpc = 0; + m->online = 1; + + /* + * CAUTION: no time sync done, etc. + */ + DBG("Wait for the thunderbirds!\n"); + while(!active.thunderbirdsarego) + ; + wrmsr(0x10, sys->epoch); + m->rdtsc = rdtsc(); + + print("cpu%d color %d role %s tsc %lld\n", + m->machno, corecolor(m->machno), n[m->nixtype], m->rdtsc); + switch(m->nixtype){ + case NIXAC: + acmmuswitch(); + acinit(); + adec(&active.nbooting); + ainc(&active.nonline); /* this was commented out */ + acsched(); + panic("squidboy"); + break; + case NIXTC: + /* + * We only need the idt and syscall entry point actually. + * At boot time the boot processor might set our role after + * we have decided to become an AC. + */ + vsvminit(MACHSTKSZ, NIXTC); + + /* + * Enable the timer interrupt. + */ + apicpri(0); + + timersinit(); + adec(&active.nbooting); + ainc(&active.nonline); /* this was commented out */ + + schedinit(); + break; + } + panic("squidboy returns (type %d)", m->nixtype); +} + +static void +testiccs(void) +{ + int i; + Mach *mp; + extern void testicc(int); + + /* setup arguments for all */ + for(i = 1; i < MACHMAX; i++) + if((mp = sys->machptr[i]) != nil && mp->online != 0) + if(mp->nixtype == NIXAC) + testicc(i); + print("bootcore: all cores done\n"); +} + +/* + * Rendezvous with other cores. Set roles for those that came + * up online, and wait until they are initialized. + * Sync TSC with them. + * We assume other processors that could boot had time to + * set online to 1 by now. + */ +static void +nixsquids(void) +{ + Mach *mp; + int i; + uvlong now, start; + + for(i = 1; i < MACHMAX; i++) + if((mp = sys->machptr[i]) != nil && mp->online != 0){ + /* + * Inter-core calls. A ensure *mp->iccall and mp->icargs + * go into different cache lines. + */ + mp->icc = mallocalign(sizeof *m->icc, ICCLNSZ, 0, 0); + mp->icc->fn = nil; + if(i < initialTCs){ + conf.nmach++; + mp->nixtype = NIXTC; + } + ainc(&active.nbooting); + } + sys->epoch = rdtsc(); + mfence(); + wrmsr(0x10, sys->epoch); + m->rdtsc = rdtsc(); + active.thunderbirdsarego = 1; + start = fastticks2us(fastticks(nil)); + do{ + now = fastticks2us(fastticks(nil)); + }while(active.nbooting > 0 && now - start < 1000000) + ; + if(active.nbooting > 0) + print("cpu0: %d cores couldn't start\n", active.nbooting); + active.nbooting = 0; +} + +void +DONE(void) +{ + print("DONE\n"); + prflush(); + delay(10000); + ndnr(); +} + +void +HERE(void) +{ + print("here\n"); + prflush(); + delay(5000); +} + +void +main(u32int ax, u32int bx) +{ + vlong hz; + + memset(edata, 0, end - edata); + + /* + * ilock via i8250enable via i8250console + * needs m->machno, sys->machptr[] set, and + * also 'up' set to nil. + */ + cgapost(sizeof(uintptr)*8); + memset(m, 0, sizeof(Mach)); + m->machno = 0; + m->online = 1; + m->nixtype = NIXTC; + sys->machptr[m->machno] = &sys->mach; + m->stack = PTR2UINT(sys->machstk); + m->vsvm = sys->vsvmpage; + up = nil; + active.nonline = 1; + active.exiting = 0; + active.nbooting = 0; + asminit(); + multiboot(ax, bx, 0); + options(oargc, oargv); + crapoptions(); + + /* + * Need something for initial delays + * until a timebase is worked out. + */ + m->cpuhz = 2000000000ll; + m->cpumhz = 2000; + + cgainit(); + i8250console("0"); + consputs = cgaconsputs; + + vsvminit(MACHSTKSZ, NIXTC); + + conf.nmach = 1; + + fmtinit(); + print("\nNIX\n"); + if(vflag){ + print("&ax = %#p, ax = %#ux, bx = %#ux\n", &ax, ax, bx); + multiboot(ax, bx, vflag); + } + + m->perf.period = 1; + if((hz = archhz()) != 0ll){ + m->cpuhz = hz; + m->cyclefreq = hz; + m->cpumhz = hz/1000000ll; + } + + /* + * Mmuinit before meminit because it + * flushes the TLB via m->pml4->pa. + */ + mmuinit(); + + ioinit(); + kbdinit(); + meminit(); + confinit(); + archinit(); + mallocinit(); + + /* + * Acpiinit will cause the first malloc + * call to happen. + * If the system dies here it's probably due + * to malloc not being initialised + * correctly, or the data segment is misaligned + * (it's amazing how far you can get with + * things like that completely broken). + */ + acpiinit(); + + umeminit(); + trapinit(); + printinit(); + + /* + * This is necessary with GRUB and QEMU. + * Without it an interrupt can occur at a weird vector, + * because the vector base is likely different, causing + * havoc. Do it before any APIC initialisation. + */ + i8259init(32); + + + procinit0(); + mpsinit(maxcores); + apiconline(); + sipi(); + + timersinit(); + kbdenable(); + fpuinit(); + psinit(conf.nproc); + initimage(); + links(); + devtabreset(); + pageinit(); + swapinit(); + userinit(); + nixsquids(); +testiccs(); +print("schedinit...\n"); + schedinit(); +} + +void +init0(void) +{ + char buf[2*KNAMELEN]; + + up->nerrlab = 0; + +// if(consuart == nil) +// i8250console("0"); + spllo(); + + /* + * These are o.k. because rootinit is null. + * Then early kproc's will have a root and dot. + */ + up->slash = namec("#/", Atodir, 0, 0); + pathclose(up->slash->path); + up->slash->path = newpath("/"); + up->dot = cclone(up->slash); + + devtabinit(); + + if(!waserror()){ + snprint(buf, sizeof(buf), "%s %s", "AMD64", conffile); + ksetenv("terminal", buf, 0); + ksetenv("cputype", "amd64", 0); + if(cpuserver) + ksetenv("service", "cpu", 0); + else + ksetenv("service", "terminal", 0); + ksetenv("pgsz", "2097152", 0); + confsetenv(); + poperror(); + } + kproc("alarm", alarmkproc, 0); + touser(sp); +} + +void +bootargs(uintptr base) +{ + int i; + ulong ssize; + char **av, *p; + + /* + * Push the boot args onto the stack. + * Make sure the validaddr check in syscall won't fail + * because there are fewer than the maximum number of + * args by subtracting sizeof(up->arg). + */ + i = oargblen+1; + p = UINT2PTR(STACKALIGN(base + BIGPGSZ - sizeof(up->arg) - i)); + memmove(p, oargb, i); + + /* + * Now push argc and the argv pointers. + * This isn't strictly correct as the code jumped to by + * touser in init9.[cs] calls startboot (port/initcode.c) which + * expects arguments + * startboot(char* argv0, char* argv[]) + * not the usual (int argc, char* argv[]), but argv0 is + * unused so it doesn't matter (at the moment...). + */ + av = (char**)(p - (oargc+2)*sizeof(char*)); + ssize = base + BIGPGSZ - PTR2UINT(av); + *av++ = (char*)oargc; + for(i = 0; i < oargc; i++) + *av++ = (oargv[i] - oargb) + (p - base) + (USTKTOP - BIGPGSZ); + *av = nil; + + sp = USTKTOP - ssize; +} + +void +userinit(void) +{ + Proc *p; + Segment *s; + KMap *k; + Page *pg; + + p = newproc(); + p->pgrp = newpgrp(); + p->egrp = smalloc(sizeof(Egrp)); + p->egrp->ref = 1; + p->fgrp = dupfgrp(nil); + p->rgrp = newrgrp(); + p->procmode = 0640; + + kstrdup(&eve, ""); + kstrdup(&p->text, "*init*"); + kstrdup(&p->user, eve); + + /* + * Kernel Stack + * + * N.B. make sure there's enough space for syscall to check + * for valid args and + * space for gotolabel's return PC + * AMD64 stack must be quad-aligned. + */ + p->sched.pc = PTR2UINT(init0); + p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->arg)-sizeof(uintptr)); + p->sched.sp = STACKALIGN(p->sched.sp); + + /* + * User Stack + * + * Technically, newpage can't be called here because it + * should only be called when in a user context as it may + * try to sleep if there are no pages available, but that + * shouldn't be the case here. + */ + s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BIGPGSZ); + p->seg[SSEG] = s; + + pg = newpage(1, 0, USTKTOP-BIGPGSZ, BIGPGSZ, -1); + segpage(s, pg); + k = kmap(pg); + bootargs(VA(k)); + kunmap(k); + + /* + * Text + */ + s = newseg(SG_TEXT, UTZERO, 1); + s->flushme++; + p->seg[TSEG] = s; + pg = newpage(1, 0, UTZERO, BIGPGSZ, -1); + memset(pg->cachectl, PG_TXTFLUSH, sizeof(pg->cachectl)); + segpage(s, pg); + k = kmap(s->map[0]->pages[0]); + memmove(UINT2PTR(VA(k)), initcode, sizeof initcode); + kunmap(k); + + ready(p); +} + +void +confinit(void) +{ + int i; + + conf.npage = 0; + for(i=0; i 1000) + conf.nproc = 1000; + conf.nimage = 200; + conf.nswap = conf.nproc*80; + conf.nswppo = 4096; +} + +static void +shutdown(int ispanic) +{ + int ms, once; + + lock(&active); + if(ispanic) + active.ispanic = ispanic; + else if(m->machno == 0 && m->online == 0) + active.ispanic = 0; + once = m->online; + m->online = 0; + adec(&active.nonline); + active.exiting = 1; + unlock(&active); + + if(once) + iprint("cpu%d: exiting\n", m->machno); + + spllo(); + for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){ + delay(TK2MS(2)); + if(active.nonline == 0 && consactive() == 0) + break; + } + + if(active.ispanic && m->machno == 0){ + if(cpuserver) + delay(30000); + else + for(;;) + halt(); + } + else + delay(1000); +} + +void +reboot(void*, void*, long) +{ + panic("reboot\n"); +} + +void +exit(int ispanic) +{ + shutdown(ispanic); + archreset(); +} diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/1/runtest --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/nix/test/1/runtest Fri Feb 10 17:12:30 2012 +0000 @@ -0,0 +1,12 @@ +#!/bin/rc + +rfork ne + +# import rc functions popular among scripts, e.g. fail +# +. ../tools + +# make sure we have 32 cores running +ncores=`{wc -l /dev/sysstat | sed 's,/.*,,'} +~ $ncores 32 || fail does not have 32 cores + diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/nix/test/README Fri Feb 10 17:12:30 2012 +0000 @@ -0,0 +1,45 @@ +This is regression testing for nix. +Each directory named with a number represents a single test. +(e.g., 1/ 2/ ...) +A test directory may be also named k1, k2, k.... +All k tests run affter all std. tests. They are meant to install ad-hoc +kernels for testing. + +The script actually running the tests is runtests, which should be run from +cpustart during the machine boot process. +That is, include + test -x /cfg/$sysname/runtests && /cfg/$sysname/runtests +in your cpustart file. +It is not meant to start the testing sequence by hand. +To (re)run all the tests, you should run ./Tests instead. + +See 1/ for a template. Copy it to your own and tweak it at will. + +To start testing, run the script ./Tests in clu, which would +change the boot sequence such that the machine starts to run tests +(perhaps installing different kernels and rebooting) until all +tests have been run or one has failed. + +Each directory must contain: + +- kern: a script used to compile and install a kernel used for testing + if no such file is found, no new kernel is installed. the current one + is used. Otherwise, the indicated kernel is installed and the machine + reboots using this kernel. + +- runtest: a script used to run a test. This is mandatory. + +- whichever other files must be available for the tests to run. + +Tests generate within each test directory: + +- koutput: a file keeping the output for a kern that did run +- output: a file keeping the output for a test that did run +- FAIL: an empty file, reporting that a test did fail. + + +BEWARE that if you install a kernel for a test then that kernel is used +for all following tests. +As a convention, tests installing a kernel should be named k0, k1, ... +test 1 installs the std kernel, so that all tests use the regular kernel. + diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/T Binary file sys/src/nix/test/T has changed diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/TIMES --- a/sys/src/nix/test/TIMES Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ -A program creating 50 threads, each one making 500 system calls -that are a nop: - -6.nc -s -> using syscalls -6.nc -n -> using nixcalls -T .... -> in TC -T -c n .... -> in AC - -;; -;; -;; time T -c 8 6.nc -s - 6.nc=2 [6.nc nicc 25267 tctime 672 actime 149322] - nix=20.01u 0.11s 0.20r T -c 8 6.nc -s ... -;; time T -c 9 6.nc -s - 6.nc=2 [6.nc nicc 25267 tctime 3891 actime 133053] - nix=20.00u 0.08s 0.20r T -c 9 6.nc -s ... -;; time T -c 10 6.nc -n - 6.nc=143 [6.nc nicc 408 tctime 1219 actime 4013] - nix=2790.00u 0.01s 0.03r T -c 10 6.nc -n ... -;; time T -c 11 6.nc -n - 6.nc=147 [6.nc nicc 413 tctime 1226 actime 4137] - nix=2910.00u 0.03s 0.04r T -c 11 6.nc -n ... -;; time T 6.nc -s - nix=9980.00u 0.00s 0.02r T 6.nc -s -;; time T 6.nc -s - nix=9990.00u 0.01s 0.01r T 6.nc -s -;; time T 6.nc -n -0.00u 0.00s 0.06r T 6.nc -n -;; nix=22831time T 6.nc -n -0.01u 0.00s 0.06r T 6.nc -n -;; nix=20953 - - -init: starting /bin/rc -/* - !6c -FVTw nc.c && 6l -o 6.nc nc.6 - */ - - -#include -#include - -static int dosyscall; -extern int sysr1(void); - -void -thr(int , void *[]) -{ - int i, n; - - for(i = 0; i < 500; i++){ - if(dosyscall) - n = sysr1(); - else - n = tsyscall(gettid(), gettid()); - USED(n); - if(0)print("t%d: rc %d\n", gettid(), n); - } -} - -void -thrmain(int argc, void *argv[]) -{ - int i, id; - - for(i = 0; i < 50; i++){ - if(0)print("t%d: arg[%d] = %s\n", gettid(), i, argv[i]); - id = newthr("thr", thr, argc, argv); - USED(id); - if(0)print("t%d: newthr %d\n", gettid(), id); - } -} - -void -main(int argc, char *argv[]) -{ - ARGBEGIN{ - case 's': - dosyscall = 1; - break; - case 'n': - dosyscall = 0; - break; - }ARGEND; - - nixsyscall(); - newthr("thrmain", thrmain, argc, argv); - sysfatal("newthr returns"); -} - - -DONT TAKE THESE TOO SERIOUSLY: - -The time to print in the console is likely to make them false (or is it not?) - -Each process eating its full quantum prints its name: - lc >/tmp/x - rc rc lc;; -;; pwd -/sys/src/9kronsc -;; cd k8 -;; mk clean >/tmp/f >[2=1] - rc rc rc rc rc rc mk rc rc rc mk rc rc rc mk #l0t etherread4 ls ls #l0t sed sed rc rc mk rc rc rc mk rc rc mk;; -;; mk >/tmp/f > cs[2=1] - rc rc mk mk mk rc mk mk #l0t etherread4 rc etherread4 mk etherread4 rc mk mk rc mk mk mk etherread4 mk mk etherread4 mk rc rc etherread4 rc etherread4 rc etherread4 mk mk etherread4 rc etherread4 rc rc mk rc mk mk etherread4 rc etherread4 rc etherread4 mk rc rc etherread4 #l0t mk rc mk etherread4 mk etherread4 rc etherread4 rc rc etherread4 awk rc rc mk etherread4 #l0t rc rc rc rc rc etherread4 rc etherread4 rc etherread4 rc etherread4 rc etherread4 6a etherread4 awk rc rc 6a 6c rc 6a rc rc rc rc 6c 6c 6c 6a 6c 6a rc 6c 6c 6c rc 6c rc rc mk 6c rc rc 6c 6c 6c etherread4 6c 6c 6c 6c 6c etherread4 #l0t etherread4 etherread4 6c 6c 6c 6c etherread4 6c 6c etherread4 #l0t 6c 6c 6c 6c etherread4 6c etherread4 6c etherread4 6c etherread4 6c etherread4 6c 6c etherread4 6c etherread4 6c etherread4 6c etherread4 6c etherread4 6c etherread4 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c etherread4 6c etherread4 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c etherread4 6c 6c 6c etherread4 6c etherread4 6c etherread4 6c etherread4 6c 6c 6c 6c 6c etherread4 6c 6c etherread4 6c 6c 6c 6c etherread4 6c 6c etherread4 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c etherread4 6c 6c 6c etherread4 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c 6c etherread4 #l0t 6c 6c 6c etherread4 6c 6c 6c 6c 6c rc 6c 6c 6c etherread4 6c etherread4 6c rc 6c 6c 6c 6c 6c 6c rc 6c rc 6c 6c 6c rc rc rc rc rc rc 6c rc rc rc 6c 6c 6c 6c rc rc 6c 6c 6c rc mk;; ;; - -each process prints how many quanta fully consumed before exiting, -if that number is not 0. -;; mk >/tmp/f - 6a=2 6a=2 rc=1mk: no recipe to make 'random.6' in directory /sys/src/9kronsc/k8 - rc=1 awk=2 awk=5 awk=4 rc=4 rc=1 6c=3 rc=5 6c=6 6c=14 rc=2 rc=3 6c=6 rc=1 6c=9 rc=5 6c=14 rc=2 6c=12 6c=16 6c=19 rc=6 6c=14 rc=5 6c=8 6c=16 rc=4 rc=1 6c=7 rc=6 mk=8;; - -lc in k8 dir: - -ls=19, mc=3 lc=1;; ;; - - -And these are for those process that got NO -interrupt at all in its quanta. -Again, full # of quanta where that happen. -Those with number 1 could be because of their last quantum. - -;; lc -386 boot k8 libtube port test.old -9kron include libc man root w -TODO ip libseg mk test words -;; -;; pwd -/sys/src/9kron -;; cd k8 -;; mk clean >/tmp/f - mk=1;; -;; mk >/tmp/f -mk: no recipe to make 'kbd.6' in directory /sys/src/9kron/k8 - awk=2 rc=1 rc=1 6c=1 rc=1 rc=1 rc=1 6c=1 6c=1 rc=1 mk=1;; -;; ;; diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/Test --- a/sys/src/nix/test/Test Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -#!/bin/rc - -rfork e -rfork n - -cd /sys/src/nix/test -../nix -pass=PASS - -fn fatal { - echo $* >[1=2] - exit fatal -} - -fn Mk { - 6c -FVTw $1.c && 6l -o 6.$1 $1.6 -} - -rm -f *.out *.6 6.* - -Mk execac || fatal execac - -files=`{ls [a-z]*.c [a-z]*.rc >[2]/dev/null| grep -v 'execac'| grep -v '\*' } - -if(test -x *.rc) - chmod +x *.rc - -for(t in $files){ - f=`{echo $t|sed 's/\.c$//'} - cmd=() - if(~ $t *.c){ - Mk $f - cmd = `{grep '^//TEST:' $t | sed 's/..TEST://'} - } - if(~ $t *.rc) - cmd=`{grep '^#TEST:' $t | sed 's/.TEST://'} - if(~ $#cmd 0){ - if(~ $t *.c) - cmd = 6.$f - if not - cmd = $t - } - echo $cmd - echo $cmd | rc >$f.out >[2=1] - test -e $f.ok || cp $f.out $f.ok - if(diff<{sort $f.ok | sed 's/0x[a-z0-9]+//g'} <{sort $f.out | sed 's/0x[a-z0-9]+//g'}){ - echo pass - rm $f.out - } - if not{ - echo fail - pass=FAIL - } - echo -} - -echo -echo tests $pass -rm -f *.6 6.* - - diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/Tests --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/nix/test/Tests Fri Feb 10 17:12:30 2012 +0000 @@ -0,0 +1,15 @@ +#!/bin/rc + +# change the boot sequence to run tests. + +# remove stale state from tests: +rm -f [0-9]*/^(koutput output FAIL) k[0-9]*/^(koutput output FAIL) + +# arrange for them to run after rebooting +if(test -e /cfg/$sysname/_runtests) + mv /cfg/$sysname/_runtests /cfg/$sysname/runtests +if(! test -x /cfg/$sysname/runtests){ + echo there is no /cfg/$sysname/runtests + exit no +} +reboot diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/execac.c --- a/sys/src/nix/test/execac.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -#include -#include - -void -usage(void) -{ - fprint(2, "Usage: testexecap [-c core (default 0)] path [args]\n"); - exits("usage"); -} - -void -main(int argc, char *argv[]) -{ - int core = 0; - - ARGBEGIN { - case 'c': - core = atoi(EARGF(usage())); - break; - default: - print(" badflag('%c')", ARGC()); - } - ARGEND - - if (argc < 1) - usage(); - - execac(core, argv[0], &argv[0]); - print("Returned? %r\n"); -} - - - - diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/fpu.c --- a/sys/src/nix/test/fpu.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -#include -#include - -/* - ! 6c -FTVw fpu.c && 6l -o fpu fpu.6 - */ - -int s = 0; - -void -main(int , char *[]) -{ - double r; - - r = 3.1415926; - r /= 2; - if(r != 0.0) - print("hola\n"); - print("2nd\n"); - r /= 2; - if(r+1.9 != 0.0) - print("caracola\n"); - exits(nil); -} diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/fpu.ok --- a/sys/src/nix/test/fpu.ok Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -hola -2nd -caracola diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/runtests --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/nix/test/runtests Fri Feb 10 17:12:30 2012 +0000 @@ -0,0 +1,37 @@ +#!/bin/rc + +echo tests... +cd /sys/src/nix/test +. tools +failed=() +tests=[0-9]* +if(test -e k[0-9]*) + tests=($tests k[0-9]*) +for(t in $tests){ + cd $t || fail cannot cd into test $t + if(test -e FAIL) + failed=($failed $t) + if not{ + if(! test -e output && ! test -e FAIL) { + echo running test $t + if(test -x kern && ! test -e koutput){ + log running kern for test $t + if(! kern >koutput >[2=1]){ + touch FAIL + fail test $t failed + } + reboot + } + if(! runtest>output >[2=1]){ + touch FAIL + fail test $t failed + } + echo test $t ok + } + } + cd .. +} +if(! ~ $#failed 0) + echo tests $failed failed +if not + echo all tests passed diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testksem.c --- a/sys/src/nix/test/testksem.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -#include -#include - -/* - * NIX optimistic semaphores shared with the kernel testing. - ! 6c -FTVw testksem.c && 6l -o 6.testksem testksem.6 - */ - - -void -usage(void) -{ - fprint(2, "usage: %s [-ud] [n]\n", argv0); - exits("usage"); -} - -int usem; - -void -main(int argc, char *argv[]) -{ - int isup; - int fd, n; - - isup = 0; - ARGBEGIN{ - case 'u': - isup = 1; - break; - case 'd': - isup = 0; - break; - default: - usage(); - }ARGEND; - n = 10; - if(argc == 1) - n = atoi(argv[0]); - else if(argc != 0) - usage(); - - - fd = open("#=/ctl", ORDWR); - if(fd < 0) - sysfatal("devtube: %r"); - if(isup) - fprint(fd, "up %#p", &usem); - else - fprint(fd, "down %#p", &usem); - if(isup == 0) - sleep(15*1000); /* let the kernel block, to check that */ - while(n-- > 0){ - print("user: %s... s=%d\n", isup?"down":"up", usem); - if(isup) - downsem(&usem, 0); - else - upsem(&usem); - print("user: %s done\n", isup?"down":"up"); - } - exits(nil); -} diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testksem.ok --- a/sys/src/nix/test/testksem.ok Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -user: up... s=-1 -user: up done -user: up... s=0 -user: up done -user: up... s=0 -user: up done -user: up... s=0 -user: up done -user: up... s=0 -user: up done -user: up... s=0 -user: up done -user: up... s=0 -user: up done -user: up... s=0 -user: up done -user: up... s=0 -user: up done -user: up... s=0 -user: up done diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testktube.c --- a/sys/src/nix/test/testktube.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -#include -#include -#include - -/* - * NIX optimistic tubes shared with the kernel testing. - ! 6c -FTVw testktube.c && 6l -o 6.testktube testktube.6 - */ - -void -usage(void) -{ - fprint(2, "usage: %s [-sr] [n]\n", argv0); - exits("usage"); -} - - -void -main(int argc, char *argv[]) -{ - int issend; - int fd, n; - void *addr; - Tube *t; - - issend = 0; - ARGBEGIN{ - case 's': - issend = 1; - break; - case 'r': - issend = 0; - break; - default: - usage(); - }ARGEND; - n = 10; - if(argc == 1) - n = atoi(argv[0]); - else if(argc != 0) - usage(); - - - t = newtube(sizeof(void*), 5); - - fd = open("#=/ctl", ORDWR); - if(fd < 0) - sysfatal("devtube: %r"); - if(issend) - fprint(fd, "send %#p", t); - else - fprint(fd, "recv %#p", t); - if(0 && issend == 0) - sleep(15*1000); /* let the kernel block, to check that */ - while(n-- > 0){ - print("user: %s...\n", issend?"recv":"send"); - if(issend) - trecv(t, &addr); - else - tsend(t, &addr); - print("user: %s done (-> %#p)\n", issend?"recv":"send", addr); - } - exits(nil); -} diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testktube.ok --- a/sys/src/nix/test/testktube.ok Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -user: send... -user: send done (-> 0x0) -user: send... -user: send done (-> 0x0) -user: send... -user: send done (-> 0x0) -user: send... -user: send done (-> 0x0) -user: send... -user: send done (-> 0x0) -user: send... -user: send done (-> 0x0) -user: send... -user: send done (-> 0x0) -user: send... -user: send done (-> 0x0) -user: send... -user: send done (-> 0x0) -user: send... -user: send done (-> 0x0) diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testntube.c --- a/sys/src/nix/test/testntube.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -#include -#include -#include - -/* - * NIX named tubes testing. - ! 6c -FTVw ntube.c && 6l -o 6.ntube ntube.6 - */ - -void -usage(void) -{ - fprint(2, "usage: %s\n", argv0); - exits("usage"); -} - -void -main(int argc, char *argv[]) -{ - Tube *t; - char *name; - - name = argv[0]; - ARGBEGIN{ - default: - usage(); - }ARGEND; - if(argc == 1) - name = "ntube"; - else if(argc != 0) - usage(); - - name = smprint("%s!test", name); - t = namedtube(name, sizeof(ulong), 16, 1); - if(t == nil) - sysfatal("namedtube: %r"); - print("%s = %#p\n", name, t); - exits(nil); -} diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testntube.ok --- a/sys/src/nix/test/testntube.ok Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -newseg 6.testntube 0x0 0x10000 -6.testntube!test = 0xfda00058 diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testseg.c --- a/sys/src/nix/test/testseg.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - !6c seg.c && 6l -o 6.seg seg.6 - */ - -#include -#include -#include - -void -main(int argc, char*argv[]) -{ - - void *p; - uvlong va; - ulong len; - char *ep; - argv0 = argv[0]; - if(argc == 1){ - p = newseg("testseg", 0, 65535); - if(p == nil) - sysfatal("newseg: %r"); - print("%s: va %#p\n", argv[1], p); - exits(nil); - } - if(argc != 4){ - fprint(2, "usage: %s name va len\n", argv0); - exits("usage"); - } - va = strtoull(argv[2], &ep, 0); - if(*ep) - sysfatal("non numeric va"); - len = strtoul(argv[3], &ep, 0); - if(*ep) - sysfatal("non numeric len"); - p = newseg(argv[1], va, len); - if(p == nil) - sysfatal("newseg: %r"); - print("%s: va %#p\n", argv[1], p); - exits(nil); -} - diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testseg.ok --- a/sys/src/nix/test/testseg.ok Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -newseg testseg 0x0 0xffff -: va 0xfd600000 diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testusem.c --- a/sys/src/nix/test/testusem.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -#include -#include - -/* - * NIX optimistic semaphores testing. - ! 6c -FTVw usem.c && 6l -o 6.usem usem.6 - */ - -int Nprocs = 5; -int verb; - -#define vprint if(verb)print - -typedef void (*Testf)(int, int*); - -long ts; /* Plan 9 semaphore for testing */ - -void -downer(int id, int *s) -{ - vprint("%d: down...\n", id); - - /* - * non blocking - while(downsem(s, 1) < 0) - sleep(1); - */ - - /* - * blocking - */ - downsem(s, 0); - - vprint("%d: downed\n", id); - semrelease(&ts, 1); - exits(nil); -} - -void -uper(int id, int *s) -{ - vprint("%d: up...\n", id); - upsem(s); - vprint("%d: uped\n", id); - semrelease(&ts, 1); - exits(nil); -} - -void -alter(int id, int *s) -{ - - vprint("%d: alt...\n", id); - altsems(&s, 1); - vprint("%d: alted\n", id); - semrelease(&ts, 1); - exits(nil); -} - -int nprocs; - -void -semtest(void) -{ - int i, t; - int *s; - struct{ - Testf f; - int fact; - } tests[] = { - {uper, 2}, - {downer, 1}, - {alter, 1}, - }; - - s = mallocz(sizeof *s, 1); - nprocs = 0; - for(t = 0; t < nelem(tests); t++) - switch(rfork(RFPROC|RFMEM|RFNOWAIT)){ - case -1: - sysfatal("fork"); - case 0: - for(i = 0; i < tests[t].fact*Nprocs; i++) - switch(rfork(RFPROC|RFMEM|RFNOWAIT)){ - case -1: - sysfatal("fork"); - case 0: - tests[t].f(ainc(&nprocs), s); - break; - } - exits(nil); - break; - } - - for(t = 0; t < nelem(tests); t++) - for(i = 0; i < tests[t].fact*Nprocs; i++) - semacquire(&ts, 1); - semstats(); - print("val = %d\n", *s); - free(s); -} - -void -usage(void) -{ - fprint(2, "usage: %s [-v] [-n n]\n", argv0); - exits("usage"); -} - -void -main(int argc, char *argv[]) -{ - ARGBEGIN{ - case 'v': - verb++; - break; - case 'n': - Nprocs = atoi(EARGF(usage())); - break; - default: - usage(); - }ARGEND; - if(argc != 0) - usage(); - - semtest(); - exits(nil); -} diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testusem.ok --- a/sys/src/nix/test/testusem.ok Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -sleep: 0 -zsleep: 0 -wake: 0 -zwake: 0 -uup: 10 -kup: 0 -udown: 10 -kdown: 0 -ualt: 5 -kalt: 0 -val = 0 diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testutube.c --- a/sys/src/nix/test/testutube.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,178 +0,0 @@ -#include -#include -#include - -/* - * NIX tubes testing. - ! 6c -FTVw utube.c && 6l -o 6.utube utube.6 - */ - -int Nprocs = 5; - - -typedef void (*Testf)(int, Tube*); - -long ts; /* Plan 9 semaphore for testing */ -int verb; - - -#define vprint if(verb)print - -void -trecver(int id, Tube *t) -{ - ulong n; - - vprint("%d: recv...\n", id); - trecv(t, &n); - vprint("%d: recved: %uld\n", id, n); - semrelease(&ts, 1); - exits(nil); -} - -void -tsender(int id, Tube *t) -{ - ulong n; - - n = id; - vprint("%d: send...\n", id); - tsend(t, &n); - vprint("%d: sent\n", id); - semrelease(&ts, 1); - exits(nil); -} - -void -talter(int id, Tube *t) -{ - ulong n; - Talt alts[] = { - {t, &n, TRCV}, - }; - - n = id; - vprint("%d: alt...\n", id); - if(talt(alts, nelem(alts)) != 0) - abort(); - vprint("%d: alted: %uld\n", id, n); - semrelease(&ts, 1); - exits(nil); -} - -void -talterduo(int id, Tube *t) -{ - ulong n; - Tube *t2; - ulong n2; - Talt alts[] = { - {t, &n, TRCV}, - {nil, &n2, TRCV}, - }; - - t2 = newtube(sizeof(ulong), 1); - alts[1].t = t2; - - switch(rfork(RFPROC|RFMEM)){ - case -1: - sysfatal("fork"); - case 0: - sleep(1); - tsender(-id, t2); - exits(nil); - } - n = id; - vprint("%d: alt...\n", id); - switch(talt(alts, nelem(alts))){ - case 0: - break; - case 1: - vprint("%d: alting...\n", id); - trecv(t, &n); - break; - default: - sysfatal("alt"); - } - vprint("%d: alted: %uld\n", id, n); - semrelease(&ts, 1); - exits(nil); -} - -long nprocs; - -void -tubetest(void) -{ - int i, j, t; - long n; - Tube *tb; - struct{ - Testf f; - int fact; - } tests[] = { - {tsender, 1}, - {trecver, 1}, - {tsender, 1}, - {talter, 1}, - -// {tsender, 1}, -// {trecver, 1}, -// {tsender, 1}, -// {talterduo, 1}, - }; - - tb = newtube(sizeof(ulong), Nprocs/2); - for(t = 0; t < nelem(tests); t++) - switch(rfork(RFPROC|RFMEM|RFNOWAIT)){ - case -1: - sysfatal("fork"); - case 0: - n = 0; - for(j = 0; j < t; j++) - n += tests[j].fact*Nprocs; - for(i = 0; i < tests[t].fact*Nprocs; i++) - switch(rfork(RFPROC|RFMEM|RFNOWAIT)){ - case -1: - sysfatal("fork"); - case 0: - tests[t].f(n+i, tb); - break; - } - exits(nil); - break; - } - - for(t = 0; t < nelem(tests); t++) - for(i = 0; i < tests[t].fact*Nprocs; i++) - semacquire(&ts, 1); - semstats(); - print("hole %d msg %d\n", tb->nhole, tb->nmsg); -} - -void -usage(void) -{ - fprint(2, "usage: %s [-v] [-n n]\n", argv0); - exits("usage"); -} - -void -main(int argc, char *argv[]) -{ - ARGBEGIN{ - case 'v': - verb++; - break; - case 'n': - Nprocs = atoi(EARGF(usage())); - break; - default: - usage(); - }ARGEND; - if(argc != 0) - usage(); - - tubetest(); - exits(nil); -} diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testutube.ok --- a/sys/src/nix/test/testutube.ok Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -sleep: 0 -zsleep: 0 -wake: 0 -zwake: 0 -uup: 20 -kup: 0 -udown: 20 -kdown: 0 -ualt: 5 -kalt: 0 -hole 2 msg 0 diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testx.c --- a/sys/src/nix/test/testx.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - !6c x.c && 6l -o 6.x x.6 - */ - -//TEST: 6.execac -c 2 6.testx - -#include -#include - -u64int zzz = 0xdeadbeebdeadbeebull; - -void f(void); -void -f(void) -{ - if(write(2, "Pi\n", 3) == 3) - write(2, "3\n", 2); - write(2, "Pi\n", 3); -} - - -void -main(int, char*[]) -{ - int x; - int *y; - - - if(zzz == 0xdeadbeebdeadbeebull) - write(2, "Ok2\n", 4); - f(); - y = &x; - *y = 3; - write(2, "hola", 4); - if(*y == 3) - write(2, "ok\n", 3); - exits("xxx"); -} - diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testx.ok --- a/sys/src/nix/test/testx.ok Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -Ok2 -Pi -3 -Pi -holaok diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testzio.c --- a/sys/src/nix/test/testzio.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,189 +0,0 @@ -/* - !6c -FVTw testzio.c && 6l -o 6.testzio testzio.6 - */ - -//TEST: 6.testzio -#include - - -void* -mkseg(char *nm, usize size, char *type) -{ - char sname[50], name[50], cname[50], buf[50]; - int fd; - void *p; - char *rp; - uintptr va; - long n; - - seprint(sname, sname+sizeof sname, "%s%s%d", nm, type, getpid()); - seprint(name, name+sizeof name, "/mnt/seg/%s", sname); - seprint(cname, cname+sizeof cname, "%s/ctl", name); - - fd = create(name, OREAD, 0640|DMDIR); - if(fd < 0) - sysfatal("create seg: %r"); - close(fd); - fd = open(cname, ORDWR); - if(fd < 0) - sysfatal("open ctl: %r"); - if(fprint(fd, "%s 0 %uld\n", type, size) < 0) - sysfatal("write ctl: %r"); - n = pread(fd, buf, sizeof buf - 1, 0LL); - if(n <= 0) - sysfatal("read ctl: %r"); - buf[n] = 0; - if(strncmp(buf+1, "msg ", 4) != 0) - sysfatal("wrong ctl data"); - va = strtoull(buf+5, &rp, 0); - size = strtoull(rp, 0, 0); - p = (void*)va; - p = segattach(SG_CEXEC, sname, p, size); - if((uintptr)p == ~0) - sysfatal("segattach: %r"); - close(fd); - return p; -} - -static void -testzp(char *) -{ - int fd[2], n; - char buf[80]; - - print("\npipe:\n"); - if(bind("#∏", "/mnt/zp", MREPL|MCREATE) < 0) - sysfatal("bind #∏: %r"); - fd[0] = open("/mnt/zp/data", ORDWR); - if(fd[0] < 0) - sysfatal("open data: %r"); - fd[1] = open("/mnt/zp/data1", ORDWR); - if(fd[1] < 1) - sysfatal("open data1: %r"); - werrstr(""); - n = write(fd[1], "hola", 4); - print("write: %d %r\n", n); - werrstr(""); - n = write(fd[1], "hola", 4); - print("write: %d %r\n", n); - werrstr(""); - buf[0] = 0; - n = read(fd[0], buf, sizeof buf - 1); - if(n > 0) - buf[n] = 0; - print("read: %d %r '%s'\n", n, buf); - close(fd[0]); - close(fd[1]); -} - - -static void -testzp2(char *p) -{ - int fd[2], n; - char buf[80]; - Zio io[5]; - int i; - - print("\npipe:\n"); - if(bind("#∏", "/mnt/zp", MREPL|MCREATE) < 0) - sysfatal("bind #∏: %r"); - fd[0] = open("/mnt/zp/data", ORDWR); - if(fd[0] < 0) - sysfatal("open data: %r"); - fd[1] = open("/mnt/zp/data1", ORDWR); - if(fd[1] < 1) - sysfatal("open data1: %r"); - werrstr(""); - strcpy(p, "hola"); - io[0].data = p; - io[0].size = strlen(io[0].data); - io[1].data = p + 100; - strcpy(io[1].data, "caracola"); - io[1].size = strlen(io[1].data); - n = zwrite(fd[1], io, 2); - print("zwrite: %d %r\n", n); - for(i = 0; i < n; i++) - print("io[%d].size = %ld\n", i, io[i].size); - - werrstr(""); - n = zread(fd[0], io, nelem(io), sizeof buf - 1); - if(n > 0) - buf[n] = 0; - print("zread: %d %r\n", n); - for(i = 0; i < n; i++){ - print("io[%d].size = %ld\n", i, io[i].size); - if(io[i].size > 0){ - memmove(buf, io[i].data, io[i].size); - buf[io[i].size] = 0; - print("io[%d].data = '%s'\n", i, buf); - } - } - close(fd[0]); - close(fd[1]); -} - - -void -main(int, char*[]) -{ - char *us, *ks; - char msg[] = "Hi there!\n"; - char msg1[] = "Or not?\n"; - char buf[1024]; - Zio io[2]; - int n, i; - int fd; - - if(bind("#g", "/mnt/seg", MREPL|MCREATE) < 0) - sysfatal("bind #g: %r"); - us = mkseg("z", 2 * 1024 * 1024, "umsg"); - ks = mkseg("z", 2 * 1024 * 1024, "kmsg"); - print("us %#p ks %#p\n", us, ks); - - print("\nwrite from zio seg:\n"); - io[0].data = us; - io[0].size = strlen(msg); - strcpy(io[0].data, msg); - io[1].data = us+0x1000; - io[1].size = strlen(msg1); - strcpy(io[1].data, msg1); - werrstr(""); - n = zwrite(1, io, nelem(io)); - print("zwrite: %d %r\n", n); - for(i = 0; i < n; i++) - print("io[%d].size = %ld\n", i, io[i].size); - - print("\nwrite from data seg:\n"); - werrstr(""); - io[0].data = "now from the data segment\n"; - io[0].size = strlen(io[0].data); - werrstr(""); - n = zwrite(1, io, 1); - print("zwrite: %d %r\n", n); - for(i = 0; i < n; i++) - print("io[%d].size = %ld\n", i, io[i].size); - - /* read */ - print("\nread:\n"); - io[0].size = io[1].size = 0; - fd = open("/NOTICE", OREAD); - n = zread(fd, io, nelem(io), 50); - close(fd); - print("zread: %d %r\n", n); - for(i = 0; i < n; i++){ - print("io[%d].size = %ld\n", i, io[i].size); - if(io[i].size > 0){ - memmove(buf, io[i].data, io[i].size); - buf[io[i].size] = 0; - print("io[%d].data = '%s'\n", i, buf); - } - } - - testzp(us+0x2000); - testzp2(us+0x3000); - exits(nil); -} - diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/testzp.c --- a/sys/src/nix/test/testzp.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +0,0 @@ -/* - !6c -FVTw testzp.c && 6l -o 6.testzp testzp.6 - */ - - - -#include -#include - -enum{N = 10 * 1024}; - -void* -mkseg(char *nm, usize size, char *type) -{ - char sname[50], name[50], cname[50], buf[50]; - int fd; - void *p; - char *rp; - uintptr va; - long n; - - seprint(sname, sname+sizeof sname, "%s%s%d", nm, type, getpid()); - seprint(name, name+sizeof name, "/mnt/seg/%s", sname); - seprint(cname, cname+sizeof cname, "%s/ctl", name); - - fd = create(name, OREAD, 0640|DMDIR); - if(fd < 0) - sysfatal("create seg: %r"); - close(fd); - fd = open(cname, ORDWR); - if(fd < 0) - sysfatal("open ctl: %r"); - if(fprint(fd, "%s 0 %uld\n", type, size) < 0) - sysfatal("write ctl: %r"); - n = pread(fd, buf, sizeof buf - 1, 0LL); - if(n <= 0) - sysfatal("read ctl: %r"); - buf[n] = 0; - if(strncmp(buf+1, "msg ", 4) != 0) - sysfatal("wrong ctl data"); - va = strtoull(buf+5, &rp, 0); - size = strtoull(rp, 0, 0); - p = (void*)va; - p = segattach(SG_CEXEC, sname, p, size); - if((uintptr)p == ~0) - sysfatal("segattach: %r"); - close(fd); - return p; -} - -static void -testp(void) -{ - int fd[2], n; - int i; - vlong t0, t1; - char buf[8*1024]; - - print("\npipe:\n"); - pipe(fd); - switch(fork()){ - case -1: - sysfatal("fork"); - case 0: - close(fd[0]); - t0 = nsec(); - for(i = 0; i < N; i++){ - if(write(fd[1], buf, sizeof buf) != sizeof buf) - sysfatal("write: %r"); - } - t1 = nsec(); - close(fd[1]); - sleep(3 * 1000); /* do not interfere */ - print("write: %lld µs\n", (t1-t0)/1000L); - exits(nil); - default: - close(fd[1]); - t0 = nsec(); - for(i = 0;; i++){ - n = read(fd[0], buf, sizeof buf); - if(n < 0) - sysfatal("zread: %r"); - if(n == 0) - break; - } - t1 = nsec(); - print("read: %lld µs\n", (t1-t0)/1000LL); - t1 = (t1-t0)/1000LL; - print("read ok (%d reads %lld bytes/µs)\n", i, - 8LL*1024LL*(vlong)i/t1); - exits(nil); - } -} - - -static void -testzp(char *p) -{ - int fd[2], n; - Zio io[5]; - int i; - vlong t0, t1; - - print("\npipe:\n"); - if(zp(fd) < 0) - sysfatal("zp: %r"); - switch(fork()){ - case -1: - sysfatal("fork"); - case 0: - close(fd[0]); - t0 = nsec(); - for(i = 0; i < N; i++){ - io[0].data = p; - io[0].size = 8*1024; - if(zwrite(fd[1], io, 1) != 1 || - io[0].size != 8*1024) - sysfatal("zwrite: %r"); - } - t1 = nsec(); - close(fd[1]); - sleep(3 * 1000); /* do not interfere */ - print("zwrite: %lld µs\n", (t1-t0)/1000L); - exits(nil); - default: - close(fd[1]); - t0 = nsec(); - for(i = 0;; i++){ - n = zread(fd[0], io, nelem(io), 8*1024); - if(n < 0) - sysfatal("zread: %r"); - if(n == 0 || io[0].size == 0) - break; - } - t1 = nsec(); - print("zread: %lld µs\n", (t1-t0)/1000LL); - t1 = (t1-t0)/1000LL; - print("zread ok (%d 8K reads %lld bytes/µs)\n", - i, 8LL*1024LL*(vlong)i/t1); - testp(); - exits(nil); - } -} - - -void -main(int, char*[]) -{ - char *us, *ks; - - if(bind("#g", "/mnt/seg", MREPL|MCREATE) < 0) - sysfatal("bind #g: %r"); - us = mkseg("z", 2 * 1024 * 1024, "umsg"); - ks = mkseg("z", 2 * 1024 * 1024, "kmsg"); - print("us %#p ks %#p\n", us, ks); - - testzp(us); - exits(nil); -} - diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/tools --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/nix/test/tools Fri Feb 10 17:12:30 2012 +0000 @@ -0,0 +1,9 @@ +fn fail { + echo $* >[1=2] + exit fail +} + +fn log { + echo $* + echo $* >/dev/cons +} diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/usemkill.c --- a/sys/src/nix/test/usemkill.c Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#include -#include - -/* - ! 6c -FTVw usemkill.c && 6l -o usemkill usemkill.6 - */ - - -//TEST: 6.usemkill & { sleep 3 ; slay 6.usemkill|rc} -int s = 0; - -void -main(int , char *[]) -{ - - semdebug = 1; - print("down...\n"); - downsem(&s, 0); - print("could down...\n"); - exits(nil); -} diff -r fb5824366f81 -r 6301c34f4f81 sys/src/nix/test/usemkill.ok --- a/sys/src/nix/test/usemkill.ok Fri Feb 10 17:11:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -down... -downsem: 0x400000 = -1