~anjan/sxmo-check

cc74d6c10f9d604f1387fbc55937b83d4345555c — Anjandev Momi 2 years ago 7894e22 main
add check for data via wifi and modem
4 files changed, 117 insertions(+), 0 deletions(-)

M .gitignore
A example.com.html
A lib/data.sh
A spec/data_spec.sh
M .gitignore => .gitignore +1 -0
@@ 1,1 1,2 @@
.secrets
index.html

A example.com.html => example.com.html +46 -0
@@ 0,0 1,46 @@
<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
        
    }
    div {
        width: 600px;
        margin: 5em auto;
        padding: 2em;
        background-color: #fdfdff;
        border-radius: 0.5em;
        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
    }
    a:link, a:visited {
        color: #38488f;
        text-decoration: none;
    }
    @media (max-width: 700px) {
        div {
            margin: 0 auto;
            width: auto;
        }
    }
    </style>    
</head>

<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is for use in illustrative examples in documents. You may use this
    domain in literature without prior coordination or asking for permission.</p>
    <p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>

A lib/data.sh => lib/data.sh +50 -0
@@ 0,0 1,50 @@
#!/bin/sh

downloadAndCheck(){
	wgetOUT="$(wget www.example.com -O index.html)"
	if [ $? -ne 0 ]
	then
		nmcli radio wifi on # make sure wifi is turned back on before exiting in failure
		echo "$wgetOUT" >&2
		exit 1
	fi

	diff index.html example.com.html

	if [ $? -ne 0 ]
	then
		nmcli radio wifi on # make sure wifi is turned back on before exiting in failure
		echo "File downloaded from example.com and file in repo (example.com.html) differ" >&2
		exit 1
	fi
}

checkwifi() {
	downloadAndCheck
}

check4g() {
	nmcli radio wifi off
	downloadAndCheck
	nmcli radio wifi on
}

suspendAndCheckWifi() {
	[ -n "$(crontab -l)" ] && echo "your crontab must be empty" >&2 && exit 1

	T_SUSPEND_IN_SEC=600
	rtcwake -m mem -s "$T_SUSPEND_IN_SEC"

	sleep 10 # wait for wifi radio to come up
	checkwifi
}

suspendAndCheck4G() {
	[ -n "$(crontab -l)" ] && echo "your crontab must be empty" >&2 && exit 1

	T_SUSPEND_IN_SEC=600
	rtcwake -m mem -s "$T_SUSPEND_IN_SEC"

	sleep 10 # wait for modem to come up
	check4g
}

A spec/data_spec.sh => spec/data_spec.sh +20 -0
@@ 0,0 1,20 @@
Describe "Download data from www"
  Include lib/data.sh
  It 'Can use wifi'
    When call checkwifi ShellSpec
    The status should be success
  End
  It 'Can use data'
    When call check4g ShellSpec
    The status should be success
  End
  It 'Can use wifi after suspend'
    When call suspendAndCheckWifi ShellSpec
    The status should be success
  End
  It 'Can use 4G after suspend'
    When call suspendAndCheck4G ShellSpec
    The status should be success
  End
End