Skip to content
Snippets Groups Projects
Commit d19c1d21 authored by Patrick Lavoisier Wapet's avatar Patrick Lavoisier Wapet
Browse files

automatization started

parent 3dd1d1f0
No related branches found
No related tags found
No related merge requests found
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')
#!/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
print("python call is find")
\ No newline at end of file
File added
# 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)
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment