2 * Copyright (C) 2017-2018 "IoT.bzh"
3 * Author Clément Bénier <clement.benier@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
27 "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
28 "github.com/stretchr/testify/assert"
31 func InitExec(t *testing.T) string {
32 t.Logf("Create helloworld directory with app-templates")
33 /*copy helloworld from fixtures to envRootCfgDir*/
34 helloworldDir := path.Join(os.Getenv(envRootCfgDir), "helloworld")
35 cmd := exec.Command("cp", "-r", helloworldFixturesDir, helloworldDir)
38 assert.Nil(t, cmd.Run())
40 /*clone submodules app templates into helloworld*/
41 subHelloworldAppTemplateDir := path.Join(helloworldDir, "conf.d", "app-templates")
42 cmd = exec.Command("git", "clone", "https://gerrit.automotivelinux.org/gerrit/p/apps/app-templates.git", subHelloworldAppTemplateDir)
43 assert.Nil(t, cmd.Run())
47 /*flush channel with timeout*/
48 func flushChannelExec(channel chan xsapiv1.ExecOutMsg, ms time.Duration) {
53 case <-time.After(ms * time.Millisecond):
58 func TestExec(t *testing.T) {
59 helloworldDir := InitExec(t)
60 /*channel for SDK events*/
61 chSdks := make(chan xsapiv1.SDK)
63 sdk := xsapiv1.SDKInstallArgs{
65 Filename: sdkFileName,
68 ConnectSDKStateChange(t, sCli, chSdks)
69 sdkRes := installFakeSdk(t, sdk, chSdks)
71 /*check there is no project*/
72 var cfgArray []xsapiv1.FolderConfig
73 assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
74 assert.Equal(t, len(cfgArray), 0)
76 fPrj := xsapiv1.FolderConfig{
78 ClientPath: helloworldDir,
79 Type: xsapiv1.TypePathMap,
80 ClientData: "clientdatatest",
81 DataPathMap: xsapiv1.PathMapConfig{
82 ServerPath: helloworldDir,
86 var cfg xsapiv1.FolderConfig
87 assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
90 /*channel for ExecOutMsg*/
91 chExec := make(chan xsapiv1.ExecOutMsg)
93 /*connect to ExecOutEvent*/
94 sCli.Conn.On(xsapiv1.ExecOutEvent, func(ev xsapiv1.ExecOutMsg) {
98 /*cmake helloworld project with fake sdk*/
99 sdkSourceFile := path.Join(sdkRes.Path, "environment-setup-corei7-64-native-linux")
100 cmd := "source " + sdkSourceFile
102 cmd = cmd + "unset SDKTARGETSYSROOT"
104 cmd = cmd + "cd " + fPrj.ClientPath
106 cmd = cmd + "mkdir -p build"
108 cmd = cmd + "cd build"
110 cmd = cmd + "cmake .."
112 /*post exec cmd cmake*/
113 exec := xsapiv1.ExecArgs{
117 var execRes xsapiv1.ExecArgs
118 t.Logf("exec cmake cmd(%v)", cmd)
119 assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
120 flushChannelExec(chExec, 1000) //waiting for execOutMsg
122 /*make helloworld project with fake sdk*/
123 cmd = "source " + sdkSourceFile
125 cmd = cmd + "unset SDKTARGETSYSROOT"
127 cmd = cmd + "cd " + fPrj.ClientPath
129 cmd = cmd + "cd build"
133 /*post exec cmd make*/
134 t.Logf("exec make cmd(%v)", cmd)
135 assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
136 flushChannelExec(chExec, 1000) //waiting for execOutMsg
138 /*check if helloworld.so exists*/
139 t.Log("check that helloworld.so exists")
140 _, err := os.Stat(path.Join(fPrj.ClientPath, "build/helloworld/helloworld.so"))
144 assert.Nil(t, HTTPCli.Delete("/folders/"+cfg.ID, &cfg))
145 RemoveSdk(t, sdkRes, chSdks)
146 DisconnectSDKStateChange(t, sCli)