驱动的简单测试
驱动的简单测试
CF1、驱动的简单测试
在上一篇文章中,我们已经把添加驱动模块做完了,并把驱动下载到了板子上。下面将介绍一下如何测试驱动是否正常。
这个ttt驱动,我们实现了一个读、一个写的接口,就此进行简单的测试:
启动板子,进入系统,然后进入命令行(可以用串口,也可以用adb shell)
进入dev目录:
这里就可以说明: ttt 设备文件已经OK了,输入输出接口都没有问题。
当然,这里还有其他的方式去验证这个输入输出,如:
进入到 /sys/class 的 ttt 设备目录下:
power
subsystem
uevent
power
subsystem
uevent
val
2、编写C程序来测试驱动的读写
切换到root权限,并进入到android源码目录下的 external 目录:
antlr fsck_msdos libvpx skia
apache-harmony genext2fs libxml2 sonivox
apache-http giflib libxslt speex
apache-xml google-diff-match-patch libyuv sqlite
astl grub llvm srec
bison gtest lohit-fonts srtp
blktrace guava markdown stlport
bluetooth harfbuzz mesa3d strace
bouncycastle hyphenation mksh svox
bsdiff icu4c mockwebserver tagsoup
bzip2 iproute2 mtpd tcpdump
chromium ipsec-tools netcat tinyalsa
clang iptables netperf tinyxml
collada javasqlite neven tremolo
dbus javassist nist-sip v8
dhcpcd jdiff oauth valgrind
dnsmasq jhead opencv webkit
doclava jpeg openssl webp
dropbear jsilver oprofile webrtc
e2fsprogs jsr305 pcre wpa_supplicant
easymock junit ping wpa_supplicant_6
elfutils kernel-headers ping6 wpa_supplicant_8
embunit libffi ppp xmlwriter
emma libgsm proguard yaffs2
esd liblzf protobuf yapp
expat libnfc-nxp qemu zlib
eyes-free libnl-headers qemu-pc-bios
fdlibm libpcap quake
flac libphonenumber replicaisland
android-mock freetype libpng safe-iop
antlr fsck_msdos libvpx skia
apache-harmony genext2fs libxml2 sonivox
apache-http giflib libxslt speex
apache-xml google-diff-match-patch libyuv sqlite
astl grub llvm srec
bison gtest lohit-fonts srtp
blktrace guava markdown stlport
bluetooth harfbuzz mesa3d strace
bouncycastle hyphenation mksh svox
bsdiff icu4c mockwebserver tagsoup
bzip2 iproute2 mtpd tcpdump
chromium ipsec-tools netcat tinyalsa
clang iptables netperf tinyxml
collada javasqlite neven tremolo
dbus javassist nist-sip v8
dhcpcd jdiff oauth valgrind
dnsmasq jhead opencv webkit
doclava jpeg openssl webp
dropbear jsilver oprofile webrtc
e2fsprogs jsr305 pcre wpa_supplicant
easymock junit ping wpa_supplicant_6
elfutils kernel-headers ping6 wpa_supplicant_8
embunit libffi ppp xmlwriter
emma libgsm proguard yaffs2
esd liblzf protobuf yapp
expat libnfc-nxp qemu zlib
eyes-free libnl-headers qemu-pc-bios
fdlibm libpcap quake
flac libphonenumber replicaisland
[cpp]
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define DEVICE_NAME "/dev/ttt"
int main(int argc, char** argv)
{
int fd = -1;
int val = 0;
fd = open(DEVICE_NAME, O_RDWR);
if(fd == -1){
printf("Failed to open device %s.\n", DEVICE_NAME);
return -1;
}
printf("Read original value:\n");
read(fd, &val, sizeof(val));
printf("%d.\n\n", val);
val = 100;
printf("Write value %d to %s.\n\n", val, DEVICE_NAME);
write(fd, &val, sizeof(val));
printf("Read the value again:\n");
read(fd, &val, sizeof(val));
printf("%d.\n\n", val);
close(fd);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define DEVICE_NAME "/dev/ttt"
int main(int argc, char** argv)
{
int fd = -1;
int val = 0;
fd = open(DEVICE_NAME, O_RDWR);
if(fd == -1){
printf("Failed to open device %s.\n", DEVICE_NAME);
return -1;
}
printf("Read original value:\n");
read(fd, &val, sizeof(val));
printf("%d.\n\n", val);
val = 100;
printf("Write value %d to %s.\n\n", val, DEVICE_NAME);
write(fd, &val, sizeof(val));
printf("Read the value again:\n");
read(fd, &val, sizeof(val));
printf("%d.\n\n", val);
close(fd);
return 0;
}
创建对应的Android.mk配置文件:
[plain]
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/external/yapp/tttapp# gedit Android.mk
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/external/yapp/tttapp# gedit Android.mk
Android.mk 文件内容如下:
[cpp] view plaincopyprint?LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := tttapp
LOCAL_SRC_FILES := tttapp.c
include $(BUILD_EXECUTABLE)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := tttapp
LOCAL_SRC_FILES := tttapp.c
include $(BUILD_EXECUTABLE)
C程序编写完了,下面进行编译:
回到android的源码目录,并执行envsetup.sh:
[plain]
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# ls
abi build device hardware out system
bionic cts docs libcore packages v8.log
bootable dalvik external Makefile prebuilt vendor
boot.img development frameworks ndk sdk
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# . build/envsetup.sh
including device/moto/stingray/vendorsetup.sh
including device/moto/wingray/vendorsetup.sh
including device/samsung/crespo4g/vendorsetup.sh
including device/samsung/crespo/vendorsetup.sh
including device/samsung/maguro/vendorsetup.sh
including device/samsung/smdkc110/vendorsetup.sh
including device/samsung/smdkv210/vendorsetup.sh
including device/samsung/torospr/vendorsetup.sh
including device/samsung/toro/vendorsetup.sh
including device/samsung/tuna/vendorsetup.sh
including device/ti/panda/vendorsetup.sh
including sdk/bash_completion/adb.bash
including device/moto/stingray/vendorsetup.sh
including device/moto/wingray/vendorsetup.sh
including device/samsung/crespo4g/vendorsetup.sh
including device/samsung/crespo/vendorsetup.sh
including device/samsung/maguro/vendorsetup.sh
including device/samsung/smdkc110/vendorsetup.sh
including device/samsung/smdkv210/vendorsetup.sh
including device/samsung/torospr/vendorsetup.sh
including device/samsung/toro/vendorsetup.sh
including device/samsung/tuna/vendorsetup.sh
including device/ti/panda/vendorsetup.sh
including sdk/bash_completion/adb.bash============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.0.4
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=IMM76I
============================================
target thumb C: tttapp <= external/yapp/tttapp/tttapp.c
target Executable: tttapp (out/target/product/generic/obj/EXECUTABLES/tttapp_intermediates/LINKED/tttapp)
target Symbolic: tttapp (out/target/product/generic/symbols/system/bin/tttapp)
target Strip: tttapp (out/target/product/generic/obj/EXECUTABLES/tttapp_intermediates/tttapp)
Install: out/target/product/generic/system/bin/tttapp
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.0.4
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=IMM76I
============================================
target thumb C: tttapp <= external/yapp/tttapp/tttapp.c
target Executable: tttapp (out/target/product/generic/obj/EXECUTABLES/tttapp_intermediates/LINKED/tttapp)
target Symbolic: tttapp (out/target/product/generic/symbols/system/bin/tttapp)
target Strip: tttapp (out/target/product/generic/obj/EXECUTABLES/tttapp_intermediates/tttapp)
Install: out/target/product/generic/system/bin/tttapp
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2#
这样就表示编译成功了,我们看一下这个对应的执行程序是否已经生成:
[plain]
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# ls -l out/target/product/generic/system/bin/tttapp
-rwxr-xr-x 1 root root 5524 2013-04-02 11:04 out/target/product/generic/system/bin/tttapp
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2#
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# ls -l out/target/product/generic/system/bin/tttapp
-rwxr-xr-x 1 root root 5524 2013-04-02 11:04 out/target/product/generic/system/bin/tttapp
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# 这样就表示生成了对应的 可执行程序。
好,现在我们把这个生成的 tttapp 程序拷贝到 SD卡上,然后放到板子上去执行。
我这里是放到了U盘上面,从U盘中把tttapp 拷贝到板子上的/data目录中去:
[plain]
root@android:/mnt # ls usb
D3GOther.exe
EBOOT.bin
EBOOT.nb0
IRDA_X.exe
LOST.DIR
MapTools.exe
NK.BIN
NK_2G.bin
NK_3G.bin
NK_3G_y.BIN
NK_src.bin
RFIDForProduce.exe
RFIDTest.exe
RFID_X.exe
STEPLDR.bin
STEPLDR.nb0
SwitchTools.exe
WINCE 6软件
android-samsung-dev_20110830.tar.gz
barscan.exe
bbk
hello
htcbjwdm.inf
tttapp
ubuntu-11.10-desktop-i386.iso
凯立德地图
机身å·ç (MC60端).exe
root@android:/mnt #
root@android:/mnt # ls
asec
ext_sd
obb
sdcard
secure
usb
root@android:/mnt # cd usb/
root@android:/mnt/usb # ls
D3GOther.exe
EBOOT.bin
EBOOT.nb0
IRDA_X.exe
LOST.DIR
MapTools.exe
NK.BIN
NK_2G.bin
NK_3G.bin
NK_3G_y.BIN
NK_src.bin
RFIDForProduce.exe
RFIDTest.exe
RFID_X.exe
STEPLDR.bin
STEPLDR.nb0
SwitchTools.exe
WINCE 6软件
android-samsung-dev_20110830.tar.gz
barscan.exe
bbk
hello
htcbjwdm.inf
tttapp
ubuntu-11.10-desktop-i386.iso
凯立德地图
æ [ttt]: ttt_read().
[ttt]: ttt_write().
[ttt]: ttt_read().
[ttt]: ttt_release().
Read original value:
123.
Write value 100 to /dev/ttt.
Read the value again:
100.
D3GOther.exe
EBOOT.bin
EBOOT.nb0
IRDA_X.exe
LOST.DIR
MapTools.exe
NK.BIN
NK_2G.bin
NK_3G.bin
NK_3G_y.BIN
NK_src.bin
RFIDForProduce.exe
RFIDTest.exe
RFID_X.exe
STEPLDR.bin
STEPLDR.nb0
SwitchTools.exe
WINCE 6软件
android-samsung-dev_20110830.tar.gz
barscan.exe
bbk
hello
htcbjwdm.inf
tttapp
ubuntu-11.10-desktop-i386.iso
凯立德地图
D3GOther.exe
EBOOT.bin
EBOOT.nb0
IRDA_X.exe
LOST.DIR
MapTools.exe
NK.BIN
NK_2G.bin
NK_3G.bin
NK_3G_y.BIN
NK_src.bin
RFIDForProduce.exe
RFIDTest.exe
RFID_X.exe
STEPLDR.bin
STEPLDR.nb0
SwitchTools.exe
WINCE 6软件
android-samsung-dev_20110830.tar.gz
barscan.exe
bbk
hello
htcbjwdm.inf
tttapp
[ttt]: ttt_open().
[ttt]: ttt_read().
[ttt]: ttt_write().
[ttt]: ttt_read().
[ttt]: ttt_release().
Read original value:
123.
Write value 100 to /dev/ttt.
Read the value again:
100.
拷贝的过程中,出现了一些情况,cp指令不可用,使用cat指令就OK了。由上面最后的几句信息,可以看出这个C程序成功了。测试驱动OK了。
到此,驱动的测试就完了。下一篇将会介绍编写对应的HAL硬件抽象层来访问内核驱动
相关文章
- 暂无相关文章
用户评论