aboutsummaryrefslogtreecommitdiff
path: root/VexRiscv/src/test/python/gcloud
diff options
context:
space:
mode:
Diffstat (limited to 'VexRiscv/src/test/python/gcloud')
-rw-r--r--VexRiscv/src/test/python/gcloud/.gitignore2
-rw-r--r--VexRiscv/src/test/python/gcloud/gcloud.py54
-rw-r--r--VexRiscv/src/test/python/gcloud/makefile0
-rwxr-xr-xVexRiscv/src/test/python/gcloud/remotePull.py10
-rwxr-xr-xVexRiscv/src/test/python/gcloud/remoteTest.py22
-rw-r--r--VexRiscv/src/test/python/gcloud/run.sh24
-rwxr-xr-xVexRiscv/src/test/python/gcloud/stopScript.sh4
-rwxr-xr-xVexRiscv/src/test/python/gcloud/try.py27
8 files changed, 143 insertions, 0 deletions
diff --git a/VexRiscv/src/test/python/gcloud/.gitignore b/VexRiscv/src/test/python/gcloud/.gitignore
new file mode 100644
index 0000000..9622174
--- /dev/null
+++ b/VexRiscv/src/test/python/gcloud/.gitignore
@@ -0,0 +1,2 @@
+/gcloud.pyc
+*.tar.gz
diff --git a/VexRiscv/src/test/python/gcloud/gcloud.py b/VexRiscv/src/test/python/gcloud/gcloud.py
new file mode 100644
index 0000000..4641124
--- /dev/null
+++ b/VexRiscv/src/test/python/gcloud/gcloud.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+from os import system
+from sys import argv
+import time
+
+class GCInstance:
+ def __init__(self, name):
+ self.instance = name
+ self.project = "ivory-infusion-209508"
+ self.zone = "europe-west1-b"
+
+ def local(self, cmd):
+ print(cmd)
+ system(cmd)
+
+ def createCustom(self, cores=1, ram=1024):
+ self.create("custom-{}-{}".format(cores,ram))
+
+ #n1-highcpu-8
+ def create(self, machine="f1-micro", args = "--preemptible"):
+ self.delete()
+ self.local('gcloud beta compute --project=ivory-infusion-209508 instances create {} --zone=europe-west1-b --machine-type={} --subnet=default --network-tier=PREMIUM --no-restart-on-failure --maintenance-policy=TERMINATE {} --service-account=470010940365-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --disk=name=miaou,device-name=miaou,mode=rw,boot=yes'.format(self.instance, machine, args))
+
+
+ def stopScript(self, script):
+ self.local('gcloud compute --project {} instances add-metadata {} --metadata-from-file shutdown-script={} --zone "{}"'.format(self.project, self.instance, script, self.zone))
+
+ def start(self):
+ self.local('gcloud compute --project "{}" instances start --zone "{}" "{}"'.format(self.project, self.zone, self.instance)) # --machine-type=f1-micro
+ time.sleep(60)
+
+
+ def stopHours(self, hours):
+ self.remote('sudo shutdown -P +{}'.format(int(hours*60)))
+
+ def stop(self):
+ self.remote('sudo shutdown -P now')
+
+ def delete(self):
+ self.local('gcloud compute --project "{}" instances delete "{}" --zone "{}" --keep-disks all --quiet'.format(self.project, self.instance, self.zone))
+
+ def remote(self, cmd):
+ self.local('gcloud compute --project "{}" ssh --zone "{}" "{}" -- "{}"'.format(self.project, self.zone, self.instance, cmd))
+
+ def localToRemote(self, source, target):
+ self.remote("rm -rf {}".format(target))
+ self.local('gcloud compute --project "{}" scp --zone "{}" {} {}:{}'.format(self.project, self.zone, source, self.instance, target))
+
+ def remoteToLocal(self, source, target):
+ self.remote("rm -rf {}".format(target))
+ self.local('gcloud compute --project "{}" scp --zone "{}" {}:{} {}'.format(self.project, self.zone, self.instance, source, target))
+
+#setsid nohup (sbt test;sudo poweroff) &> sbtTest.txt
diff --git a/VexRiscv/src/test/python/gcloud/makefile b/VexRiscv/src/test/python/gcloud/makefile
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/VexRiscv/src/test/python/gcloud/makefile
diff --git a/VexRiscv/src/test/python/gcloud/remotePull.py b/VexRiscv/src/test/python/gcloud/remotePull.py
new file mode 100755
index 0000000..7160579
--- /dev/null
+++ b/VexRiscv/src/test/python/gcloud/remotePull.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+
+from gcloud import GCInstance
+
+gci = GCInstance("vexriscv")
+gci.create()
+gci.start()
+gci.remoteToLocal("run.txt","run.txt")
+gci.stop()
+gci.delete()
diff --git a/VexRiscv/src/test/python/gcloud/remoteTest.py b/VexRiscv/src/test/python/gcloud/remoteTest.py
new file mode 100755
index 0000000..37bd029
--- /dev/null
+++ b/VexRiscv/src/test/python/gcloud/remoteTest.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+from os import system
+from sys import argv
+
+from gcloud import GCInstance
+
+gci = GCInstance("vexriscv")
+#gci.create("n1-standard-1")
+gci.create("n1-highcpu-8")
+gci.start()
+gci.stopHours(20)
+gci.stopScript("src/test/python/gcloud/stopScript.sh")
+
+gci.local("rm -rf archive.tar.gz; git ls-files -z | xargs -0 tar -czf archive.tar.gz")
+gci.localToRemote("archive.tar.gz", "")
+gci.local("cd ../SpinalHDL; rm -rf spinal.tar.gz; git ls-files -z | xargs -0 tar -czf spinal.tar.gz")
+gci.localToRemote("../SpinalHDL/spinal.tar.gz", "")
+gci.localToRemote("src/test/python/gcloud/run.sh", "")
+gci.remote("rm -rf run.txt; setsid nohup sh run.sh &> run.txt")
+
+#setsid nohup (sbt test;sudo poweroff) &> sbtTest.txt
diff --git a/VexRiscv/src/test/python/gcloud/run.sh b/VexRiscv/src/test/python/gcloud/run.sh
new file mode 100644
index 0000000..02c17f9
--- /dev/null
+++ b/VexRiscv/src/test/python/gcloud/run.sh
@@ -0,0 +1,24 @@
+rm -rf sbtTest.txt
+rm -rf VexRiscv
+rm -rf SpinalHDL
+#git clone https://github.com/SpinalHDL/SpinalHDL.git -b dev
+mkdir SpinalHDL
+tar -xzf spinal.tar.gz -C SpinalHDL
+mkdir VexRiscv
+tar -xzf archive.tar.gz -C VexRiscv
+cd VexRiscv
+sudo git init
+sudo git add *
+sudo git commit -m miaou
+export VEXRISCV_REGRESSION_CONFIG_COUNT=128
+export VEXRISCV_REGRESSION_FREERTOS_COUNT=30
+sbt test
+cd ..
+
+#sudo apt-get install mailutils + https://cloud.google.com/compute/docs/tutorials/sending-mail/using-mailgun
+echo "Miaou" | mail -s "VexRiscv cloud" charles.papon.90@gmail.com -A run.txt
+sleep 15
+
+sudo shutdown -P now
+
+
diff --git a/VexRiscv/src/test/python/gcloud/stopScript.sh b/VexRiscv/src/test/python/gcloud/stopScript.sh
new file mode 100755
index 0000000..e3c6ea9
--- /dev/null
+++ b/VexRiscv/src/test/python/gcloud/stopScript.sh
@@ -0,0 +1,4 @@
+#! /bin/bash
+
+echo "preempted :(" | mail -s "VexRiscv cloud" charles.papon.90@gmail.com -A /home/spinalvm/run.txt
+sleep 10
diff --git a/VexRiscv/src/test/python/gcloud/try.py b/VexRiscv/src/test/python/gcloud/try.py
new file mode 100755
index 0000000..650beb4
--- /dev/null
+++ b/VexRiscv/src/test/python/gcloud/try.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+from os import system
+from sys import argv
+
+project = "ivory-infusion-209508"
+zone = "europe-west1-b"
+instance = "miaou"
+
+def local(cmd):
+ print(cmd)
+ system(cmd)
+
+def remote(cmd):
+ cmd = 'gcloud compute --project "{}" ssh --zone "{}" "{}" -- "{}"'.format(project, zone, instance, cmd)
+ print(cmd)
+ system(cmd)
+
+def localToRemote(source, target):
+ remote("rm -rf target")
+ cmd = 'gcloud compute --project "{}" scp --zone "{}" {} {}:{}'.format(project, zone, source, instance, target)
+ print(cmd)
+ system(cmd)
+
+#local("sbt test &")
+local("python -c 'from os import system; system(\"(sbt test >> sbtTest.txt) &\")'")
+#python -c 'from os import system; system("sbt test")' &