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 helloworldDir := path.Join(os.Getenv(envRootCfgDir), "helloworld")
33 cmd := exec.Command("cp", "-r", helloworldFixturesDir, helloworldDir)
36 assert.Nil(t, cmd.Run())
37 subHelloworldAppTemplateDir := path.Join(helloworldDir, "conf.d", "app-templates")
38 cmd = exec.Command("git", "clone", "https://gerrit.automotivelinux.org/gerrit/p/apps/app-templates.git", subHelloworldAppTemplateDir)
39 assert.Nil(t, cmd.Run())
43 /*flush channel with timeout*/
44 func flushChannelExec(channel chan xsapiv1.ExecOutMsg, ms time.Duration) {
49 case <-time.After(ms * time.Millisecond):
54 func TestExec(t *testing.T) {
55 helloworldDir := InitExec(t)
56 chSdks := make(chan xsapiv1.SDK)
58 sdk := xsapiv1.SDKInstallArgs{
60 Filename: sdkFileName,
63 ConnectSDKStateChange(t, sCli, chSdks)
64 sdkRes := installFakeSdk(t, sdk, chSdks)
66 var cfgArray []xsapiv1.FolderConfig
67 assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
68 assert.Equal(t, len(cfgArray), 0)
70 fPrj := xsapiv1.FolderConfig{
72 ClientPath: helloworldDir,
73 Type: xsapiv1.TypePathMap,
74 ClientData: "clientdatatest",
75 DataPathMap: xsapiv1.PathMapConfig{
76 ServerPath: helloworldDir,
79 var cfg xsapiv1.FolderConfig
80 assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
83 chExec := make(chan xsapiv1.ExecOutMsg)
85 sCli.Conn.On(xsapiv1.ExecOutEvent, func(ev xsapiv1.ExecOutMsg) {
89 sdkSourceFile := path.Join(sdkRes.Path, "environment-setup-corei7-64-native-linux")
90 cmd := "source " + sdkSourceFile
92 cmd = cmd + "unset SDKTARGETSYSROOT"
94 cmd = cmd + "cd " + fPrj.ClientPath
96 cmd = cmd + "mkdir -p build"
98 cmd = cmd + "cd build"
100 cmd = cmd + "cmake .."
102 exec := xsapiv1.ExecArgs{
106 var execRes xsapiv1.ExecArgs
107 assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
108 flushChannelExec(chExec, 1000)
110 cmd = "source " + sdkSourceFile
112 cmd = cmd + "unset SDKTARGETSYSROOT"
114 cmd = cmd + "cd " + fPrj.ClientPath
116 cmd = cmd + "cd build"
120 assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
121 flushChannelExec(chExec, 1000)
123 /*check afb-helloworld.so exists*/
124 _, err := os.Stat(path.Join(fPrj.ClientPath, "build/helloworld/helloworld.so"))
127 assert.Nil(t, HTTPCli.Delete("/folders/"+cfg.ID, &cfg))
129 RemoveSdk(t, sdkRes, chSdks)
130 DisconnectSDKStateChange(t, sCli)