Toby Gray 2012-11-21 14:00:31 +00:00 committed by Pete Batard
parent 94b0ccc5e5
commit 21cf6e4748
14 changed files with 1151 additions and 2 deletions

2
.gitignore vendored
View file

@ -28,6 +28,8 @@ listdevs
xusb
dpfp
dpfp_threaded
fxload
stress
*.exe
*.pc
doc/html

View file

@ -9,6 +9,10 @@ if BUILD_EXAMPLES
SUBDIRS += examples
endif
if BUILD_TESTS
SUBDIRS += tests
endif
pkgconfigdir=$(libdir)/pkgconfig
pkgconfig_DATA=libusb-1.0.pc

View file

@ -3,4 +3,4 @@
set -e
./bootstrap.sh
./configure --enable-maintainer-mode --enable-examples-build "$@"
./configure --enable-maintainer-mode --enable-examples-build --enable-tests-build "$@"

View file

@ -186,6 +186,13 @@ AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
[build_examples='no'])
AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
# Tests build
AC_ARG_ENABLE([tests-build], [AS_HELP_STRING([--enable-tests-build],
[build test applications (default n)])],
[build_tests=$enableval],
[build_tests='no'])
AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != "xno"])
# check for -fvisibility=hidden compiler support (GCC >= 3.4)
saved_cflags="$CFLAGS"
# -Werror required for cygwin
@ -222,6 +229,7 @@ AC_CONFIG_FILES([libusb-1.0.pc])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([libusb/Makefile])
AC_CONFIG_FILES([examples/Makefile])
AC_CONFIG_FILES([tests/Makefile])
AC_CONFIG_FILES([doc/Makefile])
AC_CONFIG_FILES([doc/doxygen.cfg])
AC_OUTPUT

View file

@ -1 +1 @@
#define LIBUSB_NANO 10588
#define LIBUSB_NANO 10589

View file

@ -31,6 +31,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xusb", "xusb.vcproj", "{08A
{5AB6B770-1925-48D5-ABC2-930F3259C020} = {5AB6B770-1925-48D5-ABC2-930F3259C020}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stress", "stress.vcproj", "{53942EFF-C810-458D-B3CB-EE5CE9F1E781}"
ProjectSection(WebsiteProperties) = preProject
Debug.AspNetCompiler.Debug = "True"
Release.AspNetCompiler.Debug = "False"
EndProjectSection
ProjectSection(ProjectDependencies) = postProject
{5AB6B770-1925-48D5-ABC2-930F3259C020} = {5AB6B770-1925-48D5-ABC2-930F3259C020}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -71,6 +80,14 @@ Global
{08A6FA39-21B7-4A05-9252-2F9864A5E5A4}.Release|Win32.Build.0 = Release|Win32
{08A6FA39-21B7-4A05-9252-2F9864A5E5A4}.Release|x64.ActiveCfg = Release|x64
{08A6FA39-21B7-4A05-9252-2F9864A5E5A4}.Release|x64.Build.0 = Release|x64
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Debug|Win32.ActiveCfg = Debug|Win32
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Debug|Win32.Build.0 = Debug|Win32
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Debug|x64.ActiveCfg = Debug|x64
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Debug|x64.Build.0 = Debug|x64
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Release|Win32.ActiveCfg = Release|Win32
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Release|Win32.Build.0 = Release|Win32
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Release|x64.ActiveCfg = Release|x64
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fxload", "fxload.vcxproj",
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "getopt", "getopt.vcxproj", "{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stress", "stress.vcxproj", "{53942EFF-C810-458D-B3CB-EE5CE9F1E781}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -67,6 +69,14 @@ Global
{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Release|Win32.Build.0 = Release|Win32
{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Release|x64.ActiveCfg = Release|x64
{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Release|x64.Build.0 = Release|x64
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Debug|Win32.ActiveCfg = Debug|Win32
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Debug|Win32.Build.0 = Debug|Win32
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Debug|x64.ActiveCfg = Debug|x64
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Debug|x64.Build.0 = Debug|x64
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Release|Win32.ActiveCfg = Release|Win32
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Release|Win32.Build.0 = Release|Win32
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Release|x64.ActiveCfg = Release|x64
{53942EFF-C810-458D-B3CB-EE5CE9F1E781}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

390
msvc/stress.vcproj Normal file
View file

@ -0,0 +1,390 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="stress"
ProjectGUID="{53942EFF-C810-458D-B3CB-EE5CE9F1E781}"
RootNamespace="tests"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="..\$(PlatformName)\$(ConfigurationName)\tests"
IntermediateDirectory="..\$(PlatformName)\$(ConfigurationName)\tests\$(ProjectName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\libusb"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="..\$(PlatformName)\$(ConfigurationName)\tests"
IntermediateDirectory="..\$(PlatformName)\$(ConfigurationName)\tests\$(ProjectName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\libusb"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="..\$(PlatformName)\$(ConfigurationName)\tests"
IntermediateDirectory="..\$(PlatformName)\$(ConfigurationName)\tests\$(ProjectName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\libusb"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="..\$(PlatformName)\$(ConfigurationName)\tests"
IntermediateDirectory="..\$(PlatformName)\$(ConfigurationName)\tests\$(ProjectName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\libusb"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\tests\testlib.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
Detect64BitPortabilityProblems="false"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
Detect64BitPortabilityProblems="false"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\tests\stress.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
Detect64BitPortabilityProblems="false"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
Detect64BitPortabilityProblems="false"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\tests\libusbx_testlib.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

167
msvc/stress.vcxproj Normal file
View file

@ -0,0 +1,167 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>stress</ProjectName>
<ProjectGuid>{53942EFF-C810-458D-B3CB-EE5CE9F1E781}</ProjectGuid>
<RootNamespace>tests</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)..\$(Platform)\$(Configuration)\tests\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)..\$(Platform)\$(Configuration)\tests\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)..\$(Platform)\$(Configuration)\tests\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)..\$(Platform)\$(Configuration)\tests\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)..\$(Platform)\$(Configuration)\tests\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)..\$(Platform)\$(Configuration)\tests\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)..\$(Platform)\$(Configuration)\tests\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)..\$(Platform)\$(Configuration)\tests\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<BuildLog>
<Path>$(IntDir)$(ProjectName).htm</Path>
</BuildLog>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<BuildLog>
<Path>$(IntDir)$(ProjectName).htm</Path>
</BuildLog>
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<BuildLog>
<Path>$(IntDir)$(ProjectName).htm</Path>
</BuildLog>
<ClCompile>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<BuildLog>
<Path>$(IntDir)$(ProjectName).htm</Path>
</BuildLog>
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\tests\stress.c" />
<ClCompile Include="..\tests\testlib.c" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=".\libusb_static.vcxproj">
<Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\tests\libusbx_testlib.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{28b6220e-d087-4f48-bd69-ffe0ac5bcc7a}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\tests\stress.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\tests\testlib.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\tests\libusbx_testlib.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

6
tests/Makefile.am Normal file
View file

@ -0,0 +1,6 @@
AM_CPPFLAGS = -I$(top_srcdir)/libusb
LDADD = ../libusb/libusb-1.0.la
noinst_PROGRAMS = stress
stress_SOURCES = stress.c testlib.c

106
tests/libusbx_testlib.h Normal file
View file

@ -0,0 +1,106 @@
/*
* libusbx test library helper functions
* Copyright © 2012 Toby Gray <toby.gray@realvnc.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LIBUSBX_TESTLIB_H
#define LIBUSBX_TESTLIB_H
#include <stdio.h>
#if !defined(bool)
#define bool int
#endif
#if !defined(true)
#define true (1 == 1)
#endif
#if !defined(false)
#define false (!true)
#endif
/** Values returned from a test function to indicate test result */
typedef enum {
/** Indicates that the test ran successfully. */
TEST_STATUS_SUCCESS,
/** Indicates that the test failed one or more test. */
TEST_STATUS_FAILURE,
/** Indicates that an unexpected error occurred. */
TEST_STATUS_ERROR,
/** Indicates that the test can't be run. For example this may be
* due to no suitable device being connected to perform the tests.*/
TEST_STATUS_SKIP
} libusbx_testlib_result;
/**
* Context for test library functions
*/
typedef struct {
char ** test_names;
int test_count;
bool list_tests;
bool verbose;
int output_fd;
FILE* output_file;
int null_fd;
} libusbx_testlib_ctx;
/**
* Logs some test information or state
*/
void libusbx_testlib_logf(libusbx_testlib_ctx * ctx,
const char* fmt, ...);
/**
* Function pointer for a libusbx test function.
*
* Should return TEST_STATUS_SUCCESS on success or another TEST_STATUS value.
*/
typedef libusbx_testlib_result
(*libusbx_testlib_test_function)(libusbx_testlib_ctx * ctx);
/**
* Structure holding a test description.
*/
typedef struct {
/** Human readable name of the test. */
const char * name;
/** The test library will call this function to run the test. */
libusbx_testlib_test_function function;
} libusbx_testlib_test;
/**
* Value to use at the end of a test array to indicate the last
* element.
*/
#define LIBUSBX_NULL_TEST {NULL, NULL}
/**
* Runs the tests provided.
*
* Before running any tests argc and argv will be processed
* to determine the mode of operation.
*
* \param argc The argc from main
* \param argv The argv from main
* \param tests A NULL_TEST terminated array of tests
* \return 0 on success, non-zero on failure
*/
int libusbx_testlib_run_tests(int argc,
char ** argv,
const libusbx_testlib_test * tests);
#endif //LIBUSBX_TESTLIB_H

161
tests/stress.c Normal file
View file

@ -0,0 +1,161 @@
/*
* libusbx stress test program to perform simple stress tests
* Copyright © 2012 Toby Gray <toby.gray@realvnc.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <sys/types.h>
#include <memory.h>
#include "libusb.h"
#include "libusbx_testlib.h"
/** Test that creates and destroys a single concurrent context
* 10000 times. */
static libusbx_testlib_result test_init_and_exit(libusbx_testlib_ctx * tctx)
{
libusb_context * ctx = NULL;
int i;
for (i = 0; i < 10000; ++i) {
int r = libusb_init(&ctx);
if (r != LIBUSB_SUCCESS) {
libusbx_testlib_logf(tctx,
"Failed to init libusb on iteration %d: %d",
i, r);
return TEST_STATUS_FAILURE;
}
libusb_exit(ctx);
ctx = NULL;
}
return TEST_STATUS_SUCCESS;
}
/** Tests that devices can be listed 1000 times. */
static libusbx_testlib_result test_get_device_list(libusbx_testlib_ctx * tctx)
{
libusb_context * ctx = NULL;
int r, i;
r = libusb_init(&ctx);
if (r != LIBUSB_SUCCESS) {
libusbx_testlib_logf(tctx, "Failed to init libusb: %d", r);
return TEST_STATUS_FAILURE;
}
for (i = 0; i < 1000; ++i) {
libusb_device ** device_list;
ssize_t list_size = libusb_get_device_list(ctx, &device_list);
if (list_size < 0 || device_list == NULL) {
libusbx_testlib_logf(tctx,
"Failed to get device list on iteration %d: %d (%p)",
i, -list_size, device_list);
return TEST_STATUS_FAILURE;
}
libusb_free_device_list(device_list, 1);
}
libusb_exit(ctx);
return TEST_STATUS_SUCCESS;
}
/** Tests that 100 concurrent device lists can be open at a time. */
static libusbx_testlib_result test_many_device_lists(libusbx_testlib_ctx * tctx)
{
#define LIST_COUNT 100
libusb_context * ctx = NULL;
libusb_device ** device_lists[LIST_COUNT];
int r, i;
memset(device_lists, 0, sizeof(device_lists));
r = libusb_init(&ctx);
if (r != LIBUSB_SUCCESS) {
libusbx_testlib_logf(tctx, "Failed to init libusb: %d", r);
return TEST_STATUS_FAILURE;
}
/* Create the 100 device lists. */
for (i = 0; i < LIST_COUNT; ++i) {
ssize_t list_size = libusb_get_device_list(ctx, &(device_lists[i]));
if (list_size < 0 || device_lists[i] == NULL) {
libusbx_testlib_logf(tctx,
"Failed to get device list on iteration %d: %d (%p)",
i, -list_size, device_lists[i]);
return TEST_STATUS_FAILURE;
}
}
/* Destroy the 100 device lists. */
for (i = 0; i < LIST_COUNT; ++i) {
if (device_lists[i]) {
libusb_free_device_list(device_lists[i], 1);
device_lists[i] = NULL;
}
}
libusb_exit(ctx);
return TEST_STATUS_SUCCESS;
#undef LIST_COUNT
}
/** Tests that the default context (used for various things including
* logging) works correctly when the first context created in a
* process is destroyed. */
static libusbx_testlib_result test_default_context_change(libusbx_testlib_ctx * tctx)
{
libusb_context * ctx = NULL;
int r, i;
for (i = 0; i < 100; ++i) {
/* First create a new context */
r = libusb_init(&ctx);
if (r != LIBUSB_SUCCESS) {
libusbx_testlib_logf(tctx, "Failed to init libusb: %d", r);
return TEST_STATUS_FAILURE;
}
/* Enable debug output, to be sure to use the context */
libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_DEBUG);
libusb_set_debug(ctx, LIBUSB_LOG_LEVEL_DEBUG);
/* Now create a reference to the default context */
r = libusb_init(NULL);
if (r != LIBUSB_SUCCESS) {
libusbx_testlib_logf(tctx, "Failed to init libusb: %d", r);
return TEST_STATUS_FAILURE;
}
/* Destroy the first context */
libusb_exit(ctx);
/* Destroy the default context */
libusb_exit(NULL);
}
return TEST_STATUS_SUCCESS;
}
/* Fill in the list of tests. */
static const libusbx_testlib_test tests[] = {
{"init_and_exit", &test_init_and_exit},
{"get_device_list", &test_get_device_list},
{"many_device_lists", &test_many_device_lists},
{"default_context_change", &test_default_context_change},
LIBUSBX_NULL_TEST
};
int main (int argc, char ** argv)
{
return libusbx_testlib_run_tests(argc, argv, tests);
}

253
tests/testlib.c Normal file
View file

@ -0,0 +1,253 @@
/*
* libusbx test library helper functions
* Copyright © 2012 Toby Gray <toby.gray@realvnc.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libusbx_testlib.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef _WIN32
#include <io.h>
#define dup _dup
#define dup2 _dup2
#define open _open
#define close _close
#define fdopen _fdopen
#define NULL_PATH "nul"
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
#else
#include <unistd.h>
#define NULL_PATH "/dev/null"
#endif
#define INVALID_FD -1
/**
* Converts a test result code into a human readable string.
*/
static const char* test_result_to_str(libusbx_testlib_result result)
{
switch (result) {
case TEST_STATUS_SUCCESS:
return "Success";
case TEST_STATUS_FAILURE:
return "Failure";
case TEST_STATUS_ERROR:
return "Error";
case TEST_STATUS_SKIP:
return "Skip";
default:
return "Unknown";
}
}
static void print_usage(int argc, char ** argv)
{
printf("Usage: %s [-l] [-v] [<test_name> ...]\n",
argc > 0 ? argv[0] : "test_*");
printf(" -l List available tests\n");
printf(" -v Don't redirect STDERR/STDOUT during tests\n");
}
static void cleanup_test_output(libusbx_testlib_ctx * ctx)
{
if (ctx->output_file != NULL) {
fclose(ctx->output_file);
ctx->output_file = NULL;
}
if (ctx->output_fd != INVALID_FD) {
close(ctx->output_fd);
ctx->output_fd = INVALID_FD;
}
if (ctx->null_fd != INVALID_FD) {
close(ctx->null_fd);
ctx->null_fd = INVALID_FD;
}
}
/**
* Setup test output handles
* \return zero on success, non-zero on failure
*/
static int setup_test_output(libusbx_testlib_ctx * ctx)
{
/* Keep a copy of STDOUT for test output */
ctx->output_fd = dup(STDOUT_FILENO);
if (ctx->output_fd < 0) {
ctx->output_fd = INVALID_FD;
printf("Failed to duplicate output handle: %d\n", errno);
return 1;
}
ctx->output_file = fdopen(ctx->output_fd, "w");
if (!ctx->output_file) {
cleanup_test_output(ctx);
printf("Failed to open FILE for output handle: %d\n", errno);
return 1;
}
/* Stop output to stdout and stderr from being displayed if using non-verbose output */
if (!ctx->verbose) {
/* Redirect STDOUT_FILENO and STDERR_FILENO to /dev/null or "nul"*/
ctx->null_fd = open(NULL_PATH, O_WRONLY);
if (ctx->null_fd < 0) {
ctx->null_fd = INVALID_FD;
cleanup_test_output(ctx);
printf("Failed to open null handle: %d\n", errno);
return 1;
}
if ((dup2(ctx->null_fd, STDOUT_FILENO) < 0) ||
(dup2(ctx->null_fd, STDERR_FILENO) < 0)) {
cleanup_test_output(ctx);
return 1;
}
}
return 0;
}
void libusbx_testlib_logf(libusbx_testlib_ctx * ctx,
const char* fmt, ...)
{
va_list va;
if (!ctx->output_file)
return;
va_start(va, fmt);
vfprintf(ctx->output_file, fmt, va);
va_end(va);
fprintf(ctx->output_file, "\n");
fflush(ctx->output_file);
}
int libusbx_testlib_run_tests(int argc,
char ** argv,
const libusbx_testlib_test * tests)
{
int run_count = 0;
int idx = 0;
int pass_count = 0;
int fail_count = 0;
int error_count = 0;
int skip_count = 0;
int r, j;
size_t arglen;
libusbx_testlib_result test_result;
libusbx_testlib_ctx ctx;
/* Setup default mode of operation */
ctx.test_names = NULL;
ctx.test_count = 0;
ctx.list_tests = false;
ctx.verbose = false;
ctx.output_fd = INVALID_FD;
ctx.output_file = NULL;
ctx.null_fd = INVALID_FD;
/* Parse command line options */
if (argc >= 2) {
for (j = 1; j < argc; j++) {
arglen = strlen(argv[j]);
if ( ((argv[j][0] == '-') || (argv[j][0] == '/')) &&
arglen >=2 ) {
switch (argv[j][1]) {
case 'l':
ctx.list_tests = true;
break;
case 'v':
ctx.verbose = true;
break;
default:
printf("Unknown option: '%s'\n", argv[j]);
print_usage(argc, argv);
return 1;
}
} else {
/* End of command line options, remaining must be list of tests to run */
ctx.test_names = argv + j;
ctx.test_count = argc - j;
break;
}
}
}
/* Validate command line options */
if (ctx.test_names && ctx.list_tests) {
printf("List of tests requested but test list provided\n");
print_usage(argc, argv);
return 1;
}
/* Setup test log output */
r = setup_test_output(&ctx);
if (r != 0)
return r;
/* Act on any options not related to running tests */
if (ctx.list_tests) {
while (tests[idx].function != NULL) {
libusbx_testlib_logf(&ctx, tests[idx].name);
++idx;
}
cleanup_test_output(&ctx);
return 0;
}
/* Run any requested tests */
while (tests[idx].function != NULL) {
const libusbx_testlib_test * test = &tests[idx];
++idx;
if (ctx.test_count > 0) {
/* Filtering tests to run, check if this is one of them */
int i;
for (i = 0; i < ctx.test_count; ++i) {
if (strcmp(ctx.test_names[i], test->name) == 0)
/* Matches a requested test name */
break;
}
if (i >= ctx.test_count) {
/* Failed to find a test match, so do the next loop iteration */
continue;
}
}
libusbx_testlib_logf(&ctx,
"Starting test run: %s...", test->name);
test_result = test->function(&ctx);
libusbx_testlib_logf(&ctx,
"%s (%d)",
test_result_to_str(test_result), test_result);
switch (test_result) {
case TEST_STATUS_SUCCESS: pass_count++; break;
case TEST_STATUS_FAILURE: fail_count++; break;
case TEST_STATUS_ERROR: error_count++; break;
case TEST_STATUS_SKIP: skip_count++; break;
}
++run_count;
}
libusbx_testlib_logf(&ctx, "---");
libusbx_testlib_logf(&ctx, "Ran %d tests", run_count);
libusbx_testlib_logf(&ctx, "Passed %d tests", pass_count);
libusbx_testlib_logf(&ctx, "Failed %d tests", fail_count);
libusbx_testlib_logf(&ctx, "Error in %d tests", error_count);
libusbx_testlib_logf(&ctx, "Skipped %d tests", skip_count);
cleanup_test_output(&ctx);
return pass_count != run_count;
}