Change-Id: I355f9a55e9641ce60c787b8b02f84f35bccc8e67
Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
"os/exec"
"path"
"testing"
"os/exec"
"path"
"testing"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
"github.com/stretchr/testify/assert"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
"github.com/stretchr/testify/assert"
-/*flush channel with timeout*/
-func flushChannelExec(channel chan xsapiv1.ExecOutMsg, ms time.Duration) {
- timeoutB := false
- for !timeoutB {
- select {
- case <-channel:
- case <-time.After(ms * time.Millisecond):
- timeoutB = true
- }
- }
-}
func TestExec(t *testing.T) {
helloworldDir := InitExec(t)
/*channel for SDK events*/
func TestExec(t *testing.T) {
helloworldDir := InitExec(t)
/*channel for SDK events*/
assert.NotNil(t, cfg)
/*channel for ExecOutMsg*/
assert.NotNil(t, cfg)
/*channel for ExecOutMsg*/
- chExec := make(chan xsapiv1.ExecOutMsg)
+ chExec := make(chan xsapiv1.ExecExitMsg)
defer close(chExec)
/*connect to ExecOutEvent*/
defer close(chExec)
/*connect to ExecOutEvent*/
- sCli.Conn.On(xsapiv1.ExecOutEvent, func(ev xsapiv1.ExecOutMsg) {
+ sCli.Conn.On(xsapiv1.ExecExitEvent, func(ev xsapiv1.ExecExitMsg) {
var execRes xsapiv1.ExecArgs
Debugf(t, "exec cmake cmd(%v)", cmd)
assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
var execRes xsapiv1.ExecArgs
Debugf(t, "exec cmake cmd(%v)", cmd)
assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
- flushChannelExec(chExec, 1000) //waiting for execOutMsg
+ exitMsg := <-chExec
+ assert.Equal(t, exitMsg.Code, 0)
/*make helloworld project with fake sdk*/
cmd = "source " + sdkSourceFile
/*make helloworld project with fake sdk*/
cmd = "source " + sdkSourceFile
/*post exec cmd make*/
Debugf(t, "exec make cmd(%v)", cmd)
assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
/*post exec cmd make*/
Debugf(t, "exec make cmd(%v)", cmd)
assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
- flushChannelExec(chExec, 1000) //waiting for execOutMsg
+ exitMsg = <-chExec
+ assert.Equal(t, exitMsg.Code, 0)
/*check if helloworld.so exists*/
Debug(t, "check that helloworld.so exists")
/*check if helloworld.so exists*/
Debug(t, "check that helloworld.so exists")