Skip to content

Commit

Permalink
Merge pull request #123 from kaistshadow/go-ethereum
Browse files Browse the repository at this point in the history
Go ethereum
  • Loading branch information
ygnkim authored Jan 11, 2021
2 parents 9ae9712 + 91ac8ca commit 72b3cf0
Show file tree
Hide file tree
Showing 23 changed files with 839 additions and 19 deletions.
9 changes: 7 additions & 2 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ message("-----------------------------------------------------------------------
message(" Start default dependencies build")
message("--------------------------------------------------------------------------------------")
add_subdirectory(openssl)
add_subdirectory(bdb)
add_subdirectory(curl)
add_subdirectory(bdb)

add_subdirectory(libev)

add_subdirectory(go-ethereum)

add_subdirectory(shadow_storage_manager)

if(ZCASH_OPT STREQUAL ON)
Expand Down Expand Up @@ -74,4 +78,5 @@ else(ZCASH_OPT STREQUAL ON)
message("--------------------------------------------------------------------------------------")
add_subdirectory(bitcoin)

endif(ZCASH_OPT STREQUAL ON)
endif(ZCASH_OPT STREQUAL ON)

2 changes: 1 addition & 1 deletion shadow
2 changes: 1 addition & 1 deletion tests/regtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ else(ZCASH_OPT STREQUAL ON)
add_subdirectory(native-bintest)
add_subdirectory(shadow-bitcoin)
add_subdirectory(shadow-syscalls)
endif(ZCASH_OPT STREQUAL ON)
endif(ZCASH_OPT STREQUAL ON)
22 changes: 22 additions & 0 deletions tests/regtest/shadow-golang/gotest_/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## required for independent build
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
#list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake") # Path for go Module
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "../../../../cmake")

#enable_language(go)
enable_testing()
## required for independent build
include(${CMAKE_MODULE_PATH}/golang.cmake)
include(${CMAKE_MODULE_PATH}/flags.cmake)

set(SOURCE_FILE test.go)


ADD_GO_LIBRARY(gotest ${SOURCE_FILE})


### add test
add_test(NAME regtest-go-test
COMMAND shadow gotest.config.xml
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")

44 changes: 44 additions & 0 deletions tests/regtest/shadow-golang/gotest_/gotest.config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<shadow>
<!-- our network -->
<topology>
<![CDATA[<?xml version="1.0" encoding="utf-8"?><graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key attr.name="packetloss" attr.type="double" for="edge" id="d9" />
<key attr.name="jitter" attr.type="double" for="edge" id="d8" />
<key attr.name="latency" attr.type="double" for="edge" id="d7" />
<key attr.name="asn" attr.type="int" for="node" id="d6" />
<key attr.name="type" attr.type="string" for="node" id="d5" />
<key attr.name="bandwidthup" attr.type="int" for="node" id="d4" />
<key attr.name="bandwidthdown" attr.type="int" for="node" id="d3" />
<key attr.name="geocode" attr.type="string" for="node" id="d2" />
<key attr.name="ip" attr.type="string" for="node" id="d1" />
<key attr.name="packetloss" attr.type="double" for="node" id="d0" />
<graph edgedefault="undirected">
<node id="poi-1">
<data key="d0">0.0</data>
<data key="d1">0.0.0.0</data>
<data key="d2">US</data>
<data key="d3">10000020000040</data>
<data key="d4">10000240</data>
<data key="d5">net</data>
</node>
<edge source="poi-1" target="poi-1">
<data key="d7">50.0</data>
<data key="d8">0.0</data>
<data key="d9">0.0</data>
</edge>
</graph>
</graphml>]]>
</topology>

<!-- the plug-ins we will be using -->
<plugin id="gotest" path="build/libgotest.so" />

<!-- the length of our experiment in seconds 1404101800-->
<kill time="20" />
<!-- our nodes -->

<node id="node1">
<application plugin="gotest" time="13" arguments="" />
</node>

</shadow>
30 changes: 30 additions & 0 deletions tests/regtest/shadow-golang/gotest_/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"C"
"fmt"
"time"
)

const (
timeFormat = "2006-01-02T15:04:05-0700"
termTimeFormat = "01-02|15:04:05.000"
floatFormat = 'f'
termMsgJust = 40
termCtxMaxPadding = 40
)

func fmt_printf_formatted_time() {
t := time.Now()
fmt.Printf("%s %s\n", "hello", t.Format(termTimeFormat))
fmt.Println("test passed")
}

//export mainGo
func mainGo() {
fmt_printf_formatted_time();
}

func main() {

}
22 changes: 22 additions & 0 deletions tests/regtest/shadow-golang/gotest_ioutils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## required for independent build
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
#list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake") # Path for go Module
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "../../../../cmake")

#enable_language(go)
enable_testing()
## required for independent build
include(${CMAKE_MODULE_PATH}/golang.cmake)
include(${CMAKE_MODULE_PATH}/flags.cmake)

set(SOURCE_FILE gotest_ioutils.go)


ADD_GO_LIBRARY(gotest_ioutils ${SOURCE_FILE})


### add test
add_test(NAME regtest-go-test
COMMAND shadow gotest_ioutils.config.xml
WORKING_DIRECTORY "..")

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<shadow>
<!-- our network -->
<topology>
<![CDATA[<?xml version="1.0" encoding="utf-8"?><graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key attr.name="packetloss" attr.type="double" for="edge" id="d9" />
<key attr.name="jitter" attr.type="double" for="edge" id="d8" />
<key attr.name="latency" attr.type="double" for="edge" id="d7" />
<key attr.name="asn" attr.type="int" for="node" id="d6" />
<key attr.name="type" attr.type="string" for="node" id="d5" />
<key attr.name="bandwidthup" attr.type="int" for="node" id="d4" />
<key attr.name="bandwidthdown" attr.type="int" for="node" id="d3" />
<key attr.name="geocode" attr.type="string" for="node" id="d2" />
<key attr.name="ip" attr.type="string" for="node" id="d1" />
<key attr.name="packetloss" attr.type="double" for="node" id="d0" />
<graph edgedefault="undirected">
<node id="poi-1">
<data key="d0">0.0</data>
<data key="d1">0.0.0.0</data>
<data key="d2">US</data>
<data key="d3">10000020000040</data>
<data key="d4">10000240</data>
<data key="d5">net</data>
</node>
<edge source="poi-1" target="poi-1">
<data key="d7">50.0</data>
<data key="d8">0.0</data>
<data key="d9">0.0</data>
</edge>
</graph>
</graphml>]]>
</topology>

<!-- the plug-ins we will be using -->
<plugin id="gotest_ioutils" path="build/libgotest_ioutils.so" />

<!-- the length of our experiment in seconds 1404101800-->
<kill time="20" />
<!-- our nodes -->

<node id="node1">
<application plugin="gotest_ioutils" time="13" arguments="" />
</node>

</shadow>
63 changes: 63 additions & 0 deletions tests/regtest/shadow-golang/gotest_ioutils/gotest_ioutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"C"
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
)

func check(e error) {
if e != nil {
panic(e)
}
}

func test() {
dat, err := ioutil.ReadFile("/proc/meminfo")
check(err)
fmt.Print(string(dat))

f, err := os.Open("/proc/meminfo")
check(err)

b1 := make([]byte, 5)
n1, err := f.Read(b1)
check(err)
fmt.Printf("%d bytes: %s\n", n1, string(b1[:n1]))

o2, err := f.Seek(6, 0)
check(err)
b2 := make([]byte, 2)
n2, err := f.Read(b2)
check(err)
fmt.Printf("%d bytes @ %d: ", n2, o2)
fmt.Printf("%v\n", string(b2[:n2]))

o3, err := f.Seek(6, 0)
check(err)
b3 := make([]byte, 2)
n3, err := io.ReadAtLeast(f, b3, 2)
check(err)
fmt.Printf("%d bytes @ %d: %s\n", n3, o3, string(b3))

_, err = f.Seek(0, 0)
check(err)

r4 := bufio.NewReader(f)
b4, err := r4.Peek(5)
check(err)
fmt.Printf("5 bytes: %s\n", string(b4))

f.Close()
}

//export mainGo
func mainGo() {
test()
}
func main() {

}
22 changes: 22 additions & 0 deletions tests/regtest/shadow-golang/gotest_mmap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## required for independent build
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
#list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake") # Path for go Module
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "../../../../cmake")

#enable_language(go)
enable_testing()
## required for independent build
include(${CMAKE_MODULE_PATH}/golang.cmake)
include(${CMAKE_MODULE_PATH}/flags.cmake)

set(SOURCE_FILE gotest_mmap.go)


ADD_GO_LIBRARY(gotest_mmap ${SOURCE_FILE})


### add test
add_test(NAME regtest-go-test
COMMAND shadow gotest_mmap.config.xml
WORKING_DIRECTORY "..")

44 changes: 44 additions & 0 deletions tests/regtest/shadow-golang/gotest_mmap/gotest_mmap.config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<shadow>
<!-- our network -->
<topology>
<![CDATA[<?xml version="1.0" encoding="utf-8"?><graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key attr.name="packetloss" attr.type="double" for="edge" id="d9" />
<key attr.name="jitter" attr.type="double" for="edge" id="d8" />
<key attr.name="latency" attr.type="double" for="edge" id="d7" />
<key attr.name="asn" attr.type="int" for="node" id="d6" />
<key attr.name="type" attr.type="string" for="node" id="d5" />
<key attr.name="bandwidthup" attr.type="int" for="node" id="d4" />
<key attr.name="bandwidthdown" attr.type="int" for="node" id="d3" />
<key attr.name="geocode" attr.type="string" for="node" id="d2" />
<key attr.name="ip" attr.type="string" for="node" id="d1" />
<key attr.name="packetloss" attr.type="double" for="node" id="d0" />
<graph edgedefault="undirected">
<node id="poi-1">
<data key="d0">0.0</data>
<data key="d1">0.0.0.0</data>
<data key="d2">US</data>
<data key="d3">10000020000040</data>
<data key="d4">10000240</data>
<data key="d5">net</data>
</node>
<edge source="poi-1" target="poi-1">
<data key="d7">50.0</data>
<data key="d8">0.0</data>
<data key="d9">0.0</data>
</edge>
</graph>
</graphml>]]>
</topology>

<!-- the plug-ins we will be using -->
<plugin id="gotest_mmap" path="build/libgotest_mmap.so" />

<!-- the length of our experiment in seconds 1404101800-->
<kill time="20" />
<!-- our nodes -->

<node id="node1">
<application plugin="gotest_mmap" time="13" arguments="" />
</node>

</shadow>
29 changes: 29 additions & 0 deletions tests/regtest/shadow-golang/gotest_mmap/gotest_mmap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// https://golang.org/src/syscall/mmap_unix_test.go

package main

import (
"C"
"syscall"
"fmt"
)

func TestMmap() {
b, err := syscall.Mmap(-1, 0, 4096, syscall.PROT_NONE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
if err != nil {
fmt.Printf("well\n")
}
b[0] = 'x'
if err := syscall.Munmap(b); err != nil {
fmt.Printf("well\n")
}

}

//export mainGo
func mainGo() {
TestMmap()
}
func main() {

}
22 changes: 22 additions & 0 deletions tests/regtest/shadow-golang/gotest_syscalls/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## required for independent build
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
#list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake") # Path for go Module
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "../../../../cmake")

#enable_language(go)
enable_testing()
## required for independent build
include(${CMAKE_MODULE_PATH}/golang.cmake)
include(${CMAKE_MODULE_PATH}/flags.cmake)

set(SOURCE_FILE gotest_syscalls.go)


ADD_GO_LIBRARY(gotest_syscalls ${SOURCE_FILE})


### add test
add_test(NAME regtest-go-test
COMMAND shadow gotest_syscalls.config.xml
WORKING_DIRECTORY "..")

Empty file.
Loading

0 comments on commit 72b3cf0

Please sign in to comment.