Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source code and testing scripts for basic Go server #1

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

if test $# -ne 1; then
echo "Usage: $0 <kvm_image>" 1>&2
exit 1
fi

kvm_image="$1"
debug_port="12345"

# Show script commands when run.
set -x

#-ex "hbreak lwip_socket" \
#-ex "hbreak lwip_setsockopt" \

gdb --eval-command="target remote :12345" -ex "set confirm off" -ex "set pagination off" \
# -ex "hbreak lwip_bind" \
# -ex "hbreak lwip_socket" \
-ex "c" \
-ex "disconnect" -ex "set arch i386:x86-64:intel" \
-ex "target remote localhost:$debug_port" "$kvm_image"
20 changes: 19 additions & 1 deletion helloworld.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package main

import "fmt"
import "net/http"

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello!")
}

func main() {
fmt.Println("hello world")
}

fmt.Println("Waiting")
j:=0
for i:=0; i < 1000000; i++ {
for i1:=0; i1 < 6000; i1++ {
j++
}
}
fmt.Println("Done")


http.HandleFunc("/", handler)
http.ListenAndServe(":9999", nil)
}
30 changes: 30 additions & 0 deletions run_dhcp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

if test $# -ne 1; then
echo "Usage: $0 <kvm_image>" 1>&2
exit 1
fi

kvm_image="$1"
qemu_script="/usr/local/bin/qemu-guest"
debug_port="12345"
bridge_iface="uk0"
bridge_ip="172.44.0.1"
start_ip="172.44.0.2"
end_ip="172.44.0.254"

echo "Creating bridge $bridge_iface with IP address $bridge_ip ..."
sudo brctl addbr "$bridge_iface" || true
sudo ifconfig "$bridge_iface" "$bridge_ip"

echo "Starting dnsmasq (DHCP server) listening on bridge $bridge_iface ..."
sudo dnsmasq -d \
--log-queries \
--bind-dynamic \
--interface="$bridge_iface" \
--listen-addr="$bridge_ip" \
--dhcp-range="$start_ip","$end_ip",255.255.255.0,12h > dnsmasq.log 2>&1 &
echo "Creating bridge $bridge_iface with IP address $bridge_ip ..."

echo "Starting KVM image in debug mode. GDB server listening on port $debug_port ..."
"$qemu_script" -k "$kvm_image" -b "$bridge_iface" -m 4096 -a "" -g "$debug_port" -P
22 changes: 22 additions & 0 deletions run_static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

if test $# -ne 1; then
echo "Usage: $0 <kvm_image>" 1>&2
exit 1
fi

kvm_image="$1"
qemu_script="/usr/local/bin/qemu-guest"
debug_port="12345"
bridge_iface="uk0"
bridge_ip="172.44.0.1"
ip="172.44.0.2"

echo "Creating bridge $bridge_iface with IP address $bridge_ip ..."
sudo brctl addbr "$bridge_iface" || true
sudo ifconfig "$bridge_iface" "$bridge_ip"

echo "Starting KVM image in debug mode. GDB server listening on port $debug_port ..."
"$qemu_script" -k "$kvm_image" -b "$bridge_iface" -m 4096 -a "netdev.ipv4_addr=${ip}
netdev.ipv4_gw_addr=172.44.0.1 netdev.ipv4_subnet_mask=255.255.255.0 --" \
-g "$debug_port" -P