Skip to content

Commit

Permalink
Added a unit test for ned14#7. Indeed, nedmalloc does crash when crea…
Browse files Browse the repository at this point in the history
…ting a fifth pool. This is bad.
  • Loading branch information
Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) committed Oct 22, 2012
1 parent 168bdfd commit 8ac28c8
Show file tree
Hide file tree
Showing 2 changed files with 257 additions and 0 deletions.
64 changes: 64 additions & 0 deletions unittests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* unittests.cpp
Catch various bugs reported over the years
(C) 2012 Niall Douglas
*/

#define NEDMALLOCDEPRECATED
#define NEDMALLOC_DEBUG 1
#define FULLSANITYCHECKS

#include "nedmalloc.h"
#include <stdio.h>
#include <vector>

#if !defined(USE_NEDMALLOC_DLL)
#include "nedmalloc.c"
#endif

int main(void)
{
using namespace std;
using namespace nedalloc;
// Crash when nedcreatepool is called in the fifth time
// https://github.com/ned14/nedmalloc/issues/7
printf("Testing: Crash when nedcreatepool is called in the fifth time ...\n");
{
vector<nedpool *> pools;
size_t count=0;
for(size_t n=1; n<256; n<<=1)
{
size_t oldsize=pools.size();
pools.resize(n);
for(size_t m=0; m<n; m++)
{
if(!pools[m])
{
printf("Creating pool %u ...\n", count+1);
if(!(pools[m]=nedcreatepool(0, 0))) abort();
count++;
}
}
for(size_t m=0; m<n/2; m++)
{
size_t i=rand() % n;
if(pools[i])
{
printf("Destroying pool %u ...\n", count);
neddestroypool(pools[i]);
pools[i]=0;
count--;
}
}
}
for(size_t n=0; n<pools.size(); n++)
{
if(pools[n])
{
printf("Destroying pool %u ...\n", count);
neddestroypool(pools[n]);
}
}
}

return 0;
}
193 changes: 193 additions & 0 deletions unittests.vcproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="unittests"
ProjectGUID="{94E67470-CD86-4873-80D9-B5A9DAB96045}"
RootNamespace="unittests"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
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="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
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="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=".\unittests.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

0 comments on commit 8ac28c8

Please sign in to comment.