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.
26 "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
27 "github.com/stretchr/testify/assert"
30 func InitExec(t *testing.T) string {
31 Debugf(t, "Create helloworld directory with app-templates")
32 /*copy helloworld from fixtures to envRootCfgDir*/
33 helloworldDir := path.Join(os.Getenv(envRootCfgDir), "helloworld")
34 cmd := exec.Command("cp", "-r", helloworldFixturesDir, helloworldDir)
37 assert.Nil(t, cmd.Run())
39 /*clone submodules app templates into helloworld*/
40 subHelloworldAppTemplateDir := path.Join(helloworldDir, "conf.d", "app-templates")
41 cmd = exec.Command("git", "clone", "https://gerrit.automotivelinux.org/gerrit/p/apps/app-templates.git", subHelloworldAppTemplateDir)
42 assert.Nil(t, cmd.Run())
46 func TestExec(t *testing.T) {
47 helloworldDir := InitExec(t)
48 /*channel for SDK events*/
49 chSdks := make(chan xsapiv1.SDK)
51 sdk := xsapiv1.SDKInstallArgs{
53 Filename: sdkFileName,
56 ConnectSDKStateChange(t, sCli, chSdks)
57 sdkRes := installFakeSdk(t, sdk, chSdks)
59 /*check there is no project*/
60 var cfgArray []xsapiv1.FolderConfig
61 assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
62 assert.Equal(t, len(cfgArray), 0)
64 fPrj := xsapiv1.FolderConfig{
66 ClientPath: helloworldDir,
67 Type: xsapiv1.TypePathMap,
68 ClientData: "clientdatatest",
69 DataPathMap: xsapiv1.PathMapConfig{
70 ServerPath: helloworldDir,
74 var cfg xsapiv1.FolderConfig
75 assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
78 /*channel for ExecOutMsg*/
79 chExec := make(chan xsapiv1.ExecExitMsg)
81 /*connect to ExecOutEvent*/
82 sCli.Conn.On(xsapiv1.ExecExitEvent, func(ev xsapiv1.ExecExitMsg) {
86 /*cmake helloworld project with fake sdk*/
87 sdkSourceFile := path.Join(sdkRes.Path, "environment-setup-corei7-64-native-linux")
88 cmd := "source " + sdkSourceFile
90 cmd = cmd + "unset SDKTARGETSYSROOT"
92 cmd = cmd + "cd " + fPrj.ClientPath
94 cmd = cmd + "mkdir -p build"
96 cmd = cmd + "cd build"
98 cmd = cmd + "cmake .."
100 /*post exec cmd cmake*/
101 exec := xsapiv1.ExecArgs{
105 var execRes xsapiv1.ExecArgs
106 Debugf(t, "exec cmake cmd(%v)", cmd)
107 assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
109 assert.Equal(t, exitMsg.Code, 0)
111 /*make helloworld project with fake sdk*/
112 cmd = "source " + sdkSourceFile
114 cmd = cmd + "unset SDKTARGETSYSROOT"
116 cmd = cmd + "cd " + fPrj.ClientPath
118 cmd = cmd + "cd build"
122 /*post exec cmd make*/
123 Debugf(t, "exec make cmd(%v)", cmd)
124 assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
126 assert.Equal(t, exitMsg.Code, 0)
128 /*check if helloworld.so exists*/
129 Debug(t, "check that helloworld.so exists")
130 _, err := os.Stat(path.Join(fPrj.ClientPath, "build/helloworld/helloworld.so"))
134 assert.Nil(t, HTTPCli.Delete("/folders/"+cfg.ID, &cfg))
135 RemoveSdk(t, sdkRes, chSdks)
136 DisconnectSDKStateChange(t, sCli)