summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordmitry pervushin <dmitry.pervushin@linaro.org>2013-04-30 15:03:32 +0200
committerdmitry pervushin <dmitry.pervushin@linaro.org>2013-04-30 15:03:32 +0200
commitb2e92534450a8a9f95d8c3f79dcfac727d940009 (patch)
treee80203f2a04416984e9784932b17f16b7f7a7e0d
parent02682958e7fe8f0d7c2312583f1ecec71da89d3d (diff)
downloadlinaro-android-kernel-test-b2e92534450a8a9f95d8c3f79dcfac727d940009.tar.gz
VFAT ioctl test
vfat-volid: the simple application that can retrieve fat volume id using ioctl test.sh: the test script
-rw-r--r--product.mk5
-rw-r--r--vfat-volid/Android.mk21
-rw-r--r--vfat-volid/Makefile25
-rw-r--r--vfat-volid/test.sh114
-rw-r--r--vfat-volid/vfat-volid.c96
5 files changed, 260 insertions, 1 deletions
diff --git a/product.mk b/product.mk
index 9867f2f..c95446b 100644
--- a/product.mk
+++ b/product.mk
@@ -15,10 +15,13 @@ PRODUCT_PACKAGES += alarm-dev-test \
ashmemtest-expanded \
loggerdevtest \
sync-basic \
- nl-listener
+ nl-listener \
+ vfat-volid dosfstools
+
PRODUCT_COPY_FILES += external/linaro-android-kernel-test/binder/bindertest.sh:system/bin/bindertest.sh
PRODUCT_COPY_FILES += external/linaro-android-kernel-test/linaro-android-kernel-tests.sh:system/bin/linaro-android-kernel-tests.sh
PRODUCT_COPY_FILES += external/linaro-android-kernel-test/netfilter/ipt-idletimer.sh:system/bin/ipt-idletimer.sh
+PRODUCT_COPY_FILES += external/linaro-android-kernel-test/vfat-volid/test.sh:system/bin/vfat-volid-test.sh
# put expanded ashmemtest in/out files on the device filesystem
PRODUCT_COPY_FILES += \
diff --git a/vfat-volid/Android.mk b/vfat-volid/Android.mk
new file mode 100644
index 0000000..095e0cf
--- /dev/null
+++ b/vfat-volid/Android.mk
@@ -0,0 +1,21 @@
+
+#############################################################################
+# Copyright (c) 2013 Linaro
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Linaro <linaro-dev@lists.linaro.org>
+#############################################################################
+
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := vfat-volid.c
+LOCAL_MODULE := vfat-volid
+LOCAL_MODULE_TAGS := optional tests
+
+include $(BUILD_EXECUTABLE)
diff --git a/vfat-volid/Makefile b/vfat-volid/Makefile
new file mode 100644
index 0000000..c2ffd02
--- /dev/null
+++ b/vfat-volid/Makefile
@@ -0,0 +1,25 @@
+#############################################################################
+# Copyright (c) 2013 Linaro
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Linaro <linaro-dev@lists.linaro.org>
+#############################################################################
+
+CC = $(CROSS_COMPILE)gcc
+CFLAGS = -O2 -g
+EXE = vfat-volid
+Q = @
+
+$(EXE): vfat-volid.c
+ @echo -ne "\tCC\t"
+ @echo $<
+ $(Q)$(CC) $(CFLAGS) -I. -o $@ $<
+
+clean:
+ @echo -ne "\tRM\t"
+ @echo $(EXE)
+ $(Q)$(RM) $(EXE)
diff --git a/vfat-volid/test.sh b/vfat-volid/test.sh
new file mode 100644
index 0000000..6225d45
--- /dev/null
+++ b/vfat-volid/test.sh
@@ -0,0 +1,114 @@
+#!/bin/sh
+
+FAIL_CODE=32767
+
+function do_test() {
+
+ # parameters: sizeK vfat_arg id
+
+ UUT=/tmp/$$.disk
+ MPT=/tmp/$$
+ DEV=/dev/block/loop7
+
+ step=0
+ rc=0
+
+ while true; do
+
+ step=1
+ echo "Creating disk of size $1..." | tee -a $LOG
+ dd if=/dev/zero of=$UUT bs=1024 count=$1 >> $LOG
+ rc=$?
+ if [ $rc -ne 0 ]; then
+ echo "Problems with dd" | tee -a $LOG
+ break
+ fi
+
+ step=2
+ echo "Setting up loop device $DEV"
+ losetup $DEV $UUT >> $LOG
+ rc=$?
+ if [ $rc -ne 0 ]; then
+ echo "Problems setting up loop device" | tee -a $LOG
+ break
+ fi
+
+ step=3
+ echo "Running mkfs.vfat..." | tee -a $LOG
+ mkfs.vfat $2 -i $3 $DEV >> $LOG
+ rc=$?
+ if [ $rc -ne 0 ]; then
+ echo "Problems formatting loop device" | tee -a $LOG
+ break
+ fi
+
+ step=4
+ mkdir -p $MPT
+
+ step=5
+ # argument "-t vfat" here is necessary, busybox's mount requires it
+ echo "Mounting device" | tee -a $LOG
+ mount -t vfat $DEV $MPT | tee -a $LOG
+ rc=$?
+ if [ $rc -ne 0 ]; then
+ echo "Could not mount device" | tee -a $LOG
+ break
+ fi
+
+ step=6
+ echo "Getting volume ID" | tee -a $LOG
+ v1=`/system/bin/vfat-volid --path $MPT -i`
+ v2=`/system/bin/vfat-volid --path $MPT -s`
+ rc=$?
+ if [ $rc -ne 0 ]; then
+ echo "Error when getting volume ID" | tee -a $LOG
+ break
+ fi
+
+ step=7
+ echo "Got volume IDs $v1 and $v2, should be identical" | tee -a $LOG
+ if [ x$v1 != x$3 ]; then
+ rc=$FAIL_CODE # indicate fail
+ fi
+ if [ x$v1 != x$v2 ]; then
+ rc=$FAIL_CODE # indicate fail
+ fi
+
+ break
+
+ done
+
+ # clean up
+ [ $step -gt 5 ] && umount $MPT
+ [ $step -gt 4 ] && rmdir $MPT
+ [ $step -gt 2 ] && losetup -d $DEV
+ [ $step -gt 1 ] && rm $UUT
+
+ return $rc
+}
+
+echo "Starting"
+insmod /system/modules/loop.ko
+mount -o rw,remount /
+mkdir /tmp
+
+LOG=/dev/null
+if [ $# -ge 1 ]; then
+ LOG=$1
+fi
+for FTYPE in 12 16 32; do
+ for SIZE in 360 1024 102400; do
+ for ID in 0x12347900 0x00000000 0xDEADBEEF 0xFFFFFDFD; do
+ do_test "$SIZE" "-F $FTYPE" "$ID"
+ rc=$?
+ if [ $rc -ne 0 ]; then
+ echo -en "### FAIL code = $rc" | tee -a $LOG
+ else
+ echo -en "### PASS" | tee -a $LOG
+ fi
+ echo -e " (FTYPE=$FTYPE, SIZE=$SIZE, ID=$ID)\n" | tee -a $LOG
+ done
+ done
+done
+rmmod loop
+
diff --git a/vfat-volid/vfat-volid.c b/vfat-volid/vfat-volid.c
new file mode 100644
index 0000000..91cb09b
--- /dev/null
+++ b/vfat-volid/vfat-volid.c
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Linaro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Linaro <linaro-dev@lists.linaro.org>
+ *******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/msdos_fs.h>
+
+#ifndef VFAT_IOCTL_GET_VOLUME_ID
+#warning The IOCTL code has not been defined in public headers...
+#define VFAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x12, __u32)
+#endif
+
+#ifndef VFAT_IOCTL_GET_VOLUME_ID_SAFE
+#warning The IOCTL safe code has not been defined in public headers...
+#define VFAT_IOCTL_GET_VOLUME_ID_SAFE _IOR('r', 0x13, __u32)
+#endif
+
+int main(int argc, char *argv[])
+{
+ struct option lopt[] = {
+ { "path", required_argument, NULL, 'p' },
+ { "ignore-error", no_argument, NULL, 'i' },
+ { "use-safe-ioctl", no_argument, NULL, 's' },
+ { "use-bad-addr", no_argument, NULL, 'e' },
+ { NULL, 0, NULL, 0 },
+ };
+ char * shopt = "p:ise";
+ char *device = NULL;
+ long res;
+ int h;
+ int c, opti,
+ ignore_ioctl_error = 0,
+ use_bad_addr = 0,
+ use_safe_ioctl = 0;
+ __u32 id;
+
+ while ((c = getopt_long(argc, argv, shopt, lopt, &opti)) != -1 ) {
+ switch (c) {
+ case 'p':
+ device = strdup(optarg);
+ break;
+ case 'i':
+ ignore_ioctl_error = 1;
+ break;
+ case 's':
+ use_safe_ioctl = 1;
+ break;
+ case 'e':
+ use_bad_addr = 1;
+ break;
+ default:
+ printf("Warning, unknown option!\n");
+ break;
+ }
+ }
+
+ if (!device) {
+ printf("Missing parameter, please use --path=<mounted fat partition> option\n");
+ return ENODEV;
+ }
+
+ h = open(device, O_RDONLY);
+ if (h < 0) {
+ perror("Error on open");
+ free(device);
+ return -h;
+ }
+
+ if (use_safe_ioctl) {
+ res = ioctl(h, VFAT_IOCTL_GET_VOLUME_ID_SAFE, use_bad_addr ? 0x1234 : &id);
+ } else {
+ res = ioctl(h, VFAT_IOCTL_GET_VOLUME_ID);
+ id = res;
+ }
+ if (res < 0 && !ignore_ioctl_error) {
+ perror("Error on ioctl");
+ free(device);
+ return -res;
+ }
+ printf("0x%08X", id);
+
+ free(device);
+ return 0;
+}