From d19c1d2129e30a476fbd28d20aa97ef713a85d86 Mon Sep 17 00:00:00 2001
From: plwapet <lavoisierwapet@gmail.com>
Date: Wed, 6 Jul 2022 21:37:04 +0200
Subject: [PATCH] automatization started

---
 experiment_automatization/monkey_runner.py    |  33 ++++++++++
 experiment_automatization/run_experiments.sh  |  58 ++++++++++++++++++
 experiment_automatization/test_python_call.py |   1 +
 .../__pycache__/physalia.cpython-38.pyc       | Bin 0 -> 672 bytes
 testing_monsoon_api/myscript.py               |  16 +++++
 testing_monsoon_api/powertool_script.py       |   5 ++
 6 files changed, 113 insertions(+)
 create mode 100755 experiment_automatization/monkey_runner.py
 create mode 100755 experiment_automatization/run_experiments.sh
 create mode 100755 experiment_automatization/test_python_call.py
 create mode 100755 testing_monsoon_api/__pycache__/physalia.cpython-38.pyc
 create mode 100755 testing_monsoon_api/myscript.py
 create mode 100755 testing_monsoon_api/powertool_script.py

diff --git a/experiment_automatization/monkey_runner.py b/experiment_automatization/monkey_runner.py
new file mode 100755
index 0000000..054de49
--- /dev/null
+++ b/experiment_automatization/monkey_runner.py
@@ -0,0 +1,33 @@
+from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
+
+#template file downloaded from this link https://developer.android.com/studio/test/monkeyrunner
+#parameters : 
+    # sys.argv[1] the function code to execute during experiements:
+      # 1 is for the battery drainer app
+    # sys.argv[from 2 to n] Eventually, argument related to the function to execute
+      ## for function code 1, ie the battery drainer app
+      # sys.argv[2] = package name
+      # sys.argv[3] = activity name
+
+
+
+print ("--- Inside the monkey_runner")
+# Connects to the current device, returning a MonkeyDevice object
+device = MonkeyRunner.waitForConnection()
+if sys.argv[1] == 1: #   for the battery drainer app
+    # sets a variable with the package's internal name
+    package = sys.argv[2]
+    # sets a variable with the name of an Activity in the package
+    activity = sys.argv[3]
+    # sets the name of the component to start
+    runComponent = package + '/' + activity
+    print("Monkey runner ready to process: ", runComponent)
+
+    # Presses the Menu button
+    # device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)
+
+# Takes a screenshot
+#result = device.takeSnapshot()
+
+# Writes the screenshot to a file
+#result.writeToFile('myproject/shot1.png','png')
diff --git a/experiment_automatization/run_experiments.sh b/experiment_automatization/run_experiments.sh
new file mode 100755
index 0000000..e00f967
--- /dev/null
+++ b/experiment_automatization/run_experiments.sh
@@ -0,0 +1,58 @@
+#!/usr/bin/bash
+# scritp to run experiments in 
+# some configurations
+APK_PATH__WINDOWS_SYNTAX="C:\Users\lavoi\opportunist_task_on_android\git_repositories\benchmarking_app_to_test_big_cores\app\debug\app-debug.apk"
+DRAINER_APK_PATH__WINDOWS_SYNTAX="C:\Users\lavoi\opportunist_task_on_android\git_repositories\app_to_drain_battery.apk"
+drainer_app_package_name="com.opportunistask.scheduling.benchmarking_app_to_test_big_cores"
+drainer_app_main_activity="com.opportunistask.scheduling.benchmarking_app_to_test_big_cores.MainActivity"
+adb='/mnt/c/Program Files/Android/platform-tools_r33.0.1-windows/platform-tools/adb.exe'
+python='/mnt/c/Users/lavoi/AppData/Local/Microsoft/WindowsApps/python.exe'
+experiment_battery_level="50"
+
+
+## activating the root
+"${adb}" root
+
+
+## first step (for google pixel 4a 5g) : verifying the battery level
+echo "### first step (for google pixel 4a 5g) : verifying the battery level"
+current_battery_level=$("${adb}" shell "dumpsys battery" | grep level  | cut -d ':' -f 2 | sed 's/ //g')
+current_battery_level=$(echo $current_battery_level | tr -d '\r') # To remove the DOS carriage return (^M). 
+echo "current battery level : ${current_battery_level} "
+
+if [ "$current_battery_level" -eq "$experiment_battery_level" ]; then
+    echo "Current battery level: OKAY"
+elif [  "$current_battery_level" -gt "$experiment_battery_level" ]; then
+    echo "Current battery is high, so we need to drain battery"
+    echo "----- Uninstalling drainer app"
+    "$adb" uninstall drainer_app_package_name  
+    echo "----- Installing drainer app"
+    "$adb" install "$DRAINER_APK_PATH__WINDOWS_SYNTAX"
+    
+    echo "------ Giving rights to drainer app"
+    "$adb" shell pm grant drainer_app_package_name  android.permission.DUMP   
+    "$adb" shell pm grant drainer_app_package_name android.permission.PACKAGE_USAGE_STATS  
+    "$adb" shell pm grant drainer_app_package_name android.permission.WRITE_EXTERNAL_STORAGE
+    
+    echo "----- Starting drainer app"
+    "$adb" shell  "sleep 1
+        am start -n $drainer_app_package_name/$drainer_app_main_activity"
+    
+    sleep 1
+    APP_PID=$("$adb" shell "ps -A | grep $drainer_app_package_name" | awk '{ print $2 }')
+    APP_PID=$(echo $APP_PID | tr -d '\r') # To remove the DOS carriage return (^M). 
+    echo "-----Drainer app started with PID =  $APP_PID " 
+
+    python monkey_runner.py 1 $drainer_app_package_name $drainer_app_main_activity
+
+
+elif [  "$current_battery_level" -lt "$experiment_battery_level" ]; then
+    echo "Current battery is low, so we need to wait battery"
+fi
+
+
+
+
+
+:<<'END_COMMENT'
+END_COMMENT
diff --git a/experiment_automatization/test_python_call.py b/experiment_automatization/test_python_call.py
new file mode 100755
index 0000000..9e33b57
--- /dev/null
+++ b/experiment_automatization/test_python_call.py
@@ -0,0 +1 @@
+print("python call is find")
\ No newline at end of file
diff --git a/testing_monsoon_api/__pycache__/physalia.cpython-38.pyc b/testing_monsoon_api/__pycache__/physalia.cpython-38.pyc
new file mode 100755
index 0000000000000000000000000000000000000000..07bfdb726c897f917c1e909232e51ffd848519e7
GIT binary patch
literal 672
zcmYjO&2AGh5VpO$$tKwpfmFmX*BqLC0fdTrZiR$;*#njv55cY1UfJHD^jfZY064*s
zGq1pn7eKyp>ML+!oX{#G&F7yP&wT#oaylIov|rahuYOZP{-nd94e@Y_?%yFuBB>@#
zTA8LTYZy)YOlNK0<dguDxh&*h%bG$CW%-FT1IXn_QaP4m7|6-CXofJn9zY?hEp18|
zL3u~93VloF(|hbeF6J~oJ-5bNYu?z8;Lag{!^@-BMmnqHrH3=&VfE#6vgxV%;Ru<t
zI9yvD#0uiTgHu8;@js82_8Iyax_^!k$X6=qH|!mlWIGN7Ib;|21x9a=XaBp+daO2E
zV#ArenP)K%s)bm14ba7+bIJtdM)`N*Ciw6#)U65ivPPE9*IKNts%_U<7kZ<7;6eBs
zZVeav&(wbDR2Mv73*Cz=4g9^*;OhWBD6``2UI;EaRd*jYUT7s2-6m$PH)(P{M<8@e
z-4xf`7Y{inUbUTulh6m7#E8s@`92BhPP!y4Z+FU$T^e#cet5b#2ztj-?6K?u47k;X
zcg`lB&LvIVlLV=MEKx0<#EO#^gzp`+V1gT^ge1=aRJ;6_t(CooSE-IaLMUlPD^_J?
I_Ka2ZAHP_(kpKVy

literal 0
HcmV?d00001

diff --git a/testing_monsoon_api/myscript.py b/testing_monsoon_api/myscript.py
new file mode 100755
index 0000000..d1e1a0b
--- /dev/null
+++ b/testing_monsoon_api/myscript.py
@@ -0,0 +1,16 @@
+# myscript.py
+
+import time
+from physalia.power_meters import MonsoonPowerMeter
+from physalia.energy_profiler import AndroidUseCase
+
+power_meter = MonsoonPowerMeter(voltage=3.7, serial=29363)#(voltage=3.8, serial=12886)
+#power_meter.SetUsbPassthrough(1)
+
+def run(_):
+    time.sleep(5)
+    print(" Android user case ok")
+use_case = AndroidUseCase('physalia-simple-tutorial', None, 'na', 'na', run=run)
+
+measurement = use_case.run(power_meter=power_meter)
+print(measurement)
diff --git a/testing_monsoon_api/powertool_script.py b/testing_monsoon_api/powertool_script.py
new file mode 100755
index 0000000..a274b61
--- /dev/null
+++ b/testing_monsoon_api/powertool_script.py
@@ -0,0 +1,5 @@
+import monsoon.LVPM as LVPM
+import monsoon.sampleEngine as sampleEngine
+import monsoon.Operations as op
+Mon = LVPM.Monsoon()
+Mon.setup_usb()
\ No newline at end of file
-- 
GitLab