-
Notifications
You must be signed in to change notification settings - Fork 25
/
test-custom-scenario.go
97 lines (79 loc) · 2.38 KB
/
test-custom-scenario.go
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
/**
* SPDX-License-Identifier: Apache-2.0
* © Copyright 2023 Hewlett Packard Enterprise Development LP
*/
package templates
import (
"my5G-RANTester/config"
"my5G-RANTester/internal/control_test_engine/gnb"
"my5G-RANTester/internal/control_test_engine/procedures"
"my5G-RANTester/internal/control_test_engine/ue"
"my5G-RANTester/internal/script"
"os"
"sync"
"time"
log "github.com/sirupsen/logrus"
"github.com/tetratelabs/wazero"
)
func TestWithCustomScenario(scenarioPath string) {
wg := sync.WaitGroup{}
cfg := config.GetConfig()
wg.Add(1)
gnb := gnb.InitGnb(cfg, &wg)
time.Sleep(1 * time.Second)
ueChan := make(chan procedures.UeTesterMessage)
wg.Add(1)
_ = ue.NewUE(cfg, 1, ueChan, gnb.GetInboundChannel(), &wg)
ctx, runtime := script.NewCustomScenario(scenarioPath)
_, err := runtime.NewHostModuleBuilder("env").
NewFunctionBuilder().
WithFunc(func(ueId uint32) {
ueChan <- procedures.UeTesterMessage{Type: procedures.Registration}
}).
Export("attach").
NewFunctionBuilder().
WithFunc(func(ueId uint32) {
ueChan <- procedures.UeTesterMessage{Type: procedures.Deregistration}
}).
Export("detach").
NewFunctionBuilder().
WithFunc(func(ueId uint32, pduSessionId uint8) {
ueChan <- procedures.UeTesterMessage{Type: procedures.NewPDUSession, Param: pduSessionId - 1}
}).
Export("pduSessionRequest").
NewFunctionBuilder().
WithFunc(func(ueId uint32, pduSessionId uint8) {
ueChan <- procedures.UeTesterMessage{Type: procedures.DestroyPDUSession, Param: pduSessionId - 1}
}).
Export("pduSessionRelease").
NewFunctionBuilder().
WithFunc(func(v uint32) {
time.Sleep(time.Duration(v) * time.Millisecond)
}).
Export("think").
Instantiate(ctx)
if err != nil {
log.Fatal(err)
}
// Instantiate the guest Wasm into the same runtime. It exports the `add`
// function, implemented in WebAssembly.
addWasm, err := os.ReadFile(scenarioPath)
if err != nil {
log.Fatal(err)
}
config := wazero.NewModuleConfig().
WithStdout(os.Stdout).
WithStderr(os.Stderr)
module, err := runtime.InstantiateWithConfig(ctx, addWasm, config)
if err != nil {
log.Fatal("failed to instantiate module: %v", err)
}
// Call the `add` function and print the results to the console.
ueHandler := module.ExportedFunction("ueHandler")
results, err := ueHandler.Call(ctx, 1)
if err != nil {
log.Fatal("failed to call ", err)
}
log.Info(results)
wg.Wait()
}