diff options
-rw-r--r-- | automated/linux/lamp/html/add-record.php | 24 | ||||
-rw-r--r-- | automated/linux/lamp/html/connect-db.php | 14 | ||||
-rw-r--r-- | automated/linux/lamp/html/create-db.php | 22 | ||||
-rw-r--r-- | automated/linux/lamp/html/create-table.php | 30 | ||||
-rw-r--r-- | automated/linux/lamp/html/delete-record.php | 24 | ||||
-rw-r--r-- | automated/linux/lamp/html/index.html | 11 | ||||
-rw-r--r-- | automated/linux/lamp/html/info.php | 1 | ||||
-rw-r--r-- | automated/linux/lamp/html/select-record.php | 26 | ||||
-rwxr-xr-x | automated/linux/lamp/lamp.sh | 98 | ||||
-rw-r--r-- | automated/linux/lamp/lamp.yaml | 29 |
10 files changed, 279 insertions, 0 deletions
diff --git a/automated/linux/lamp/html/add-record.php b/automated/linux/lamp/html/add-record.php new file mode 100644 index 0000000..f721677 --- /dev/null +++ b/automated/linux/lamp/html/add-record.php @@ -0,0 +1,24 @@ +<?php +$servername = "localhost"; +$username = "root"; +$password = "lamptest"; +$dbname = "myDB"; + +// Create connection +$conn = mysqli_connect($servername, $username, $password, $dbname); +// Check connection +if (!$conn) { + die("Connection failed: " . mysqli_connect_error()); +} + +$sql = "INSERT INTO MyGuests (firstname, lastname, email) +VALUES ('John', 'Doe', 'john@example.com')"; + +if (mysqli_query($conn, $sql)) { + echo "New record created successfully"; +} else { + echo "Error: " . $sql . "<br>" . mysqli_error($conn); +} + +mysqli_close($conn); +?> diff --git a/automated/linux/lamp/html/connect-db.php b/automated/linux/lamp/html/connect-db.php new file mode 100644 index 0000000..ee42caf --- /dev/null +++ b/automated/linux/lamp/html/connect-db.php @@ -0,0 +1,14 @@ +<?php +$servername = "localhost"; +$username = "root"; +$password = "lamptest"; + +// Create connection +$conn = new mysqli($servername, $username, $password); + +// Check connection +if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); +} +echo "Connected successfully"; +?> diff --git a/automated/linux/lamp/html/create-db.php b/automated/linux/lamp/html/create-db.php new file mode 100644 index 0000000..63c166b --- /dev/null +++ b/automated/linux/lamp/html/create-db.php @@ -0,0 +1,22 @@ +<?php +$servername = "localhost"; +$username = "root"; +$password = "lamptest"; + +// Create connection +$conn = new mysqli($servername, $username, $password); +// Check connection +if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +// Create database +$sql = "CREATE DATABASE myDB"; +if ($conn->query($sql) === TRUE) { + echo "Database created successfully"; +} else { + echo "Error creating database: " . $conn->error; +} + +$conn->close(); +?> diff --git a/automated/linux/lamp/html/create-table.php b/automated/linux/lamp/html/create-table.php new file mode 100644 index 0000000..740676a --- /dev/null +++ b/automated/linux/lamp/html/create-table.php @@ -0,0 +1,30 @@ +<?php +$servername = "localhost"; +$username = "root"; +$password = "lamptest"; +$dbname = "myDB"; + +// Create connection +$conn = new mysqli($servername, $username, $password, $dbname); +// Check connection +if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +// sql to create table +$sql = "CREATE TABLE MyGuests ( +id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, +firstname VARCHAR(30) NOT NULL, +lastname VARCHAR(30) NOT NULL, +email VARCHAR(50), +reg_date TIMESTAMP +)"; + +if ($conn->query($sql) === TRUE) { + echo "Table MyGuests created successfully"; +} else { + echo "Error creating table: " . $conn->error; +} + +$conn->close(); +?> diff --git a/automated/linux/lamp/html/delete-record.php b/automated/linux/lamp/html/delete-record.php new file mode 100644 index 0000000..8939c45 --- /dev/null +++ b/automated/linux/lamp/html/delete-record.php @@ -0,0 +1,24 @@ +<?php +$servername = "localhost"; +$username = "root"; +$password = "lamptest"; +$dbname = "myDB"; + +// Create connection +$conn = new mysqli($servername, $username, $password, $dbname); +// Check connection +if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +// sql to delete a record +$sql = "DELETE FROM MyGuests WHERE id=6"; + +if ($conn->query($sql) === TRUE) { + echo "Record deleted successfully"; +} else { + echo "Error deleting record: " . $conn->error; +} + +$conn->close(); +?> diff --git a/automated/linux/lamp/html/index.html b/automated/linux/lamp/html/index.html new file mode 100644 index 0000000..4529cd4 --- /dev/null +++ b/automated/linux/lamp/html/index.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<html> +<head> +<title></title> +</head> +<body> + +<h1>Test Page for the Apache HTTP Server</h1> + +</body> +</html> diff --git a/automated/linux/lamp/html/info.php b/automated/linux/lamp/html/info.php new file mode 100644 index 0000000..147cebc --- /dev/null +++ b/automated/linux/lamp/html/info.php @@ -0,0 +1 @@ +<?php phpinfo(); ?> diff --git a/automated/linux/lamp/html/select-record.php b/automated/linux/lamp/html/select-record.php new file mode 100644 index 0000000..45505f3 --- /dev/null +++ b/automated/linux/lamp/html/select-record.php @@ -0,0 +1,26 @@ +<?php +$servername = "localhost"; +$username = "root"; +$password = "lamptest"; +$dbname = "myDB"; + +// Create connection +$conn = new mysqli($servername, $username, $password, $dbname); +// Check connection +if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +$sql = "SELECT id, firstname, lastname FROM MyGuests"; +$result = $conn->query($sql); + +if ($result->num_rows > 0) { + // output data of each row + while($row = $result->fetch_assoc()) { + echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; + } +} else { + echo "0 results"; +} +$conn->close(); +?> diff --git a/automated/linux/lamp/lamp.sh b/automated/linux/lamp/lamp.sh new file mode 100755 index 0000000..2601e0b --- /dev/null +++ b/automated/linux/lamp/lamp.sh @@ -0,0 +1,98 @@ +#!/bin/sh + +. ../../lib/sh-test-lib +OUTPUT="$(pwd)/output" +RESULT_FILE="${OUTPUT}/result.txt" + +usage() { + echo "Usage: $0 [-s <true|false>]" 1>&2 + exit 1 +} + +while getopts "s:" o; do + case "$o" in + s) SKIP_INSTALL="${OPTARG}" ;; + *) usage ;; + esac +done + +! check_root && error_msg "This script must be run as root" +[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)" +mkdir -p "${OUTPUT}" + +# Install lamp and use systemctl for service management. Tested on Ubuntu 16.04, +# Debian 8, CentOS 7 and Fedora 24. systemctl should available on newer releases +# as well. +if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then + warn_msg "LAMP package installation skipped" +else + dist_name + case "${dist}" in + Debian|Ubuntu) + if [ "${dist}" = "Debian" ]; then + pkgs="apache2 mysql-server php5-mysql php5-common libapache2-mod-php5" + elif [ "${dist}" = "Ubuntu" ]; then + pkgs="apache2 mysql-server php-mysql php-common libapache2-mod-php" + fi + install_deps "curl ${pkgs}" + echo "extension=mysqli.so" >> /etc/php5/apache2/php.ini + systemctl restart apache2 + systemctl restart mysql + ;; + CentOS|Fedora) + pkgs="httpd mariadb-server mariadb php php-mysql" + install_deps "curl ${pkgs}" + systemctl start httpd.service + systemctl start mariadb + ;; + *) + error_msg "Unsupported distribution!" + esac +fi + +cp ./html/* /var/www/html/ + +# Test Apache. +curl -o "${OUPUT}/index.html" "http://localhost/index.html" +grep "Test Page for the Apache HTTP Server" "${OUPUT}/index.html" +check_return "apache2-test-page" + +# Test MySQL. +mysqladmin -u root password lamptest +mysql --user="root" --password="lamptest" -e "show databases" +check_return "mysql-show-databases" + +# Test PHP. +curl -o "${OUTPUT}/phpinfo.html" "http://localhost/info.php" +grep "PHP Version" "${OUTPUT}/phpinfo.html" +check_return "phpinfo" + +# PHP Connect to MySQL. +curl -o "${OUTPUT}/connect-db" "http://localhost/connect-db.php" +grep "Connected successfully" "${OUTPUT}/connect-db" +exit_on_fail "php-connect-db" + +# PHP Create a MySQL Database. +curl -o "${OUTPUT}/create-db" "http://localhost/create-db.php" +grep "Database created successfully" "${OUTPUT}/create-db" +check_return "php-create-db" + +# PHP Create MySQL table. +curl -o "${OUTPUT}/create-table" "http://localhost/create-table.php" +grep "Table MyGuests created successfully" "${OUTPUT}/create-table" +check_return "php-create-table" + +# PHP add record to MySQL table. +curl -o "${OUTPUT}/add-record" "http://localhost/add-record.php" +grep "New record created successfully" "${OUTPUT}/add-record" +check_return "php-add-record" + +# PHP select record from MySQL table. +curl -o "${OUTPUT}/select-record" "http://localhost/select-record.php" +grep "id: 1 - Name: John Doe" "${OUTPUT}/select-record" +check_return "php-select-record" + +# PHP delete record from MySQL table. +curl -o "${OUTPUT}/delete-record" "http://localhost/delete-record.php" +grep "Record deleted successfully" "${OUTPUT}/delete-record" +check_return "php-delete-record" diff --git a/automated/linux/lamp/lamp.yaml b/automated/linux/lamp/lamp.yaml new file mode 100644 index 0000000..fced5df --- /dev/null +++ b/automated/linux/lamp/lamp.yaml @@ -0,0 +1,29 @@ +metadata: + format: Lava-Test Test Definition 1.0 + name: lamp + description: "A LAMP stack is a group of open source software that is + typically installed together to enable a server to host + dynamic websites and web applications." + maintainer: + - chase.qi@linaro.org + os: + - debian + - ubuntu + - centos + - fedora + scope: + - functional + devices: + - mustang + - overdrive + - d02 + - d03 + +params: + SKIP_INSTALL: "False" + +run: + steps: + - cd ./automated/linux/lamp/ + - ./lamp.sh -s "${SKIP_INSTALL}" + - ../../utils/send-to-lava.sh ./output/result.txt |