stresstcl.c
3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <sys/types.h>
#include <sys/ipc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <tcl.h>
#include "os.h"
#include "em.h"
#include "ramrom.h"
#include "sys/u64gio.h"
#include "driverd.h"
#include "stressctrl.h"
#ifdef _EMULATOR
#define IOCTL emioctl
#else
#define IOCTL ioctl
#endif /* _EMULATOR */
static int giofd;
static char cmdbuf[RAMROM_BUF_SIZE];
int StressTclFly(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
StressControl *sp;
RamRomBuffer *rp;
u64_write_arg_t arg;
if(argc != 5)
{
fprintf(stderr,"StressTclFly: # of args (%d) incorrect.\n", argc);
fprintf(stderr,"usage: StressTclFly v r p y\n");
return TCL_OK;
}
rp = (RamRomBuffer *)cmdbuf;
rp->length = sizeof(long)*2 + sizeof(FlyInfo);
sp = (StressControl *)&rp->userdata[0];
sp->type = STRESS_FLY_TYPE;
sp->u_msg.fly.vel = atoi(argv[1]);
sp->u_msg.fly.r = atoi(argv[2]);
sp->u_msg.fly.p = atoi(argv[3]);
sp->u_msg.fly.y = atoi(argv[4]);
arg.buffer = cmdbuf;
arg.ramrom_addr = RAMROM_APP_READ_ADDR;
arg.nbytes = sizeof(StressControl) + sizeof(long)*10;
arg.value = HOST_APP_CMD_READY;
IOCTL(giofd, U64_SAFE_WRITE, &arg);
sginap(10);
strcpy(interp->result, "StressTclFly passed");
return TCL_OK;
}
int StressTclMode(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
StressControl *sp;
RamRomBuffer *rp;
u64_write_arg_t arg;
if(argc != 5)
{
fprintf(stderr,"StressTclMode: # of args (%d) incorrect.\n", argc);
fprintf(stderr,"usage: StressTclMode trap mode scene display");
return TCL_OK;
}
rp = (RamRomBuffer *)cmdbuf;
rp->length = sizeof(StressControl);
sp = (StressControl *)&rp->userdata[0];
sp->type = STRESS_MESSAGE_TYPE;
sp->u_msg.mode.trap = atoi(argv[1]);
sp->u_msg.mode.mode = atoi(argv[2]);
sp->u_msg.mode.scene = atoi(argv[3]);
sp->u_msg.mode.display = atoi(argv[4]);
arg.buffer = cmdbuf;
arg.ramrom_addr = RAMROM_APP_READ_ADDR;
arg.nbytes = sizeof(StressControl) + sizeof(long)*10;
arg.value = HOST_APP_CMD_READY;
IOCTL(giofd, U64_SAFE_WRITE, &arg);
sginap(10);
strcpy(interp->result, "StressTclMode passed");
return TCL_OK;
}
int StressTclConnect(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
int i, reply;
RegisterSession session;
#ifdef _EMULATOR
giofd = emopen("/dev/u64gio");
if (giofd == -1) {
fprintf(stderr, "Unable to connect with game\n");
return;
}
session.dd_header = DRIVERD_REGISTER_SESSION;
session.id = ((id_t)getpid());
for (i=0; i < 8; i++) {
write(giofd, &session, sizeof(session));
read(giofd, &reply, sizeof(reply));
if (reply == 1)
break;
sleep(1);
}
if (i == 8) {
fprintf(stderr, "stress: Unable to register with driverd (no emulate?)\n");
exit(1);
}
#else
giofd = open(DEV_U64, O_RDWR);
if (giofd == -1) {
fprintf(stderr, "stresstcl: Unable to open %s ", DEV_U64);
perror("");
return TCL_ERROR;
}
#endif /* _EMULATOR */
/*
IOCTL(giofd, U64_LISTEN, GAME_APP_DATA_READY);
read(giofd, &reply, sizeof(reply));
*/
sleep(1);
fprintf(stderr,"Ui connected to game\n");
return TCL_OK;
}
int
StressTclInit(Tcl_Interp *interp)
{
Tcl_CreateCommand(interp, "StressTclConnect", StressTclConnect, NULL, NULL);
Tcl_CreateCommand(interp, "StressTclMode", StressTclMode, NULL, NULL);
Tcl_CreateCommand(interp, "StressTclFly", StressTclFly, NULL, NULL);
strcpy(interp->result, "StressTclInit passed");
return TCL_OK;
}