private void EncoderMemUsageTemplate(LzmaCompLevel level, bool extreme) { void PrintMemUsage(ulong usage, int threads = 0) { char extremeChar = extreme ? 'e' : ' '; uint purePreset = (uint)level; string msg; if (threads == 0) { msg = $"Encoder Mem Usage (p{purePreset}{extremeChar}) = {usage / (1024 * 1024) + 1}MB ({usage}B)"; } else { msg = $"Encoder Mem Usage (p{purePreset}{extremeChar}, {threads}T) = {usage / (1024 * 1024) + 1}MB ({usage}B)"; } Console.WriteLine(msg); } ulong single = XZInit.EncoderMemUsage(level, extreme); ulong multi1 = XZInit.EncoderMultiMemUsage(level, extreme, 1); ulong multi2 = XZInit.EncoderMultiMemUsage(level, extreme, 2); PrintMemUsage(single); PrintMemUsage(multi1, 1); PrintMemUsage(multi2, 2); Assert.AreNotEqual(ulong.MaxValue, single); Assert.AreNotEqual(ulong.MaxValue, multi1); Assert.AreNotEqual(ulong.MaxValue, multi2); Assert.IsTrue(single < multi1); }
public void CpuThreads() { uint xzCoreCount = XZInit.CpuThreads(); uint bclCoreCount = (uint)Environment.ProcessorCount; Assert.AreEqual(bclCoreCount, xzCoreCount); Console.WriteLine($"Hardware CPU Threads = {xzCoreCount}"); }
public void Version() { Version verInst = XZInit.Version(); Console.WriteLine($"liblzma Version (Version) = {verInst}"); string verStr = XZInit.VersionString(); Console.WriteLine($"liblzma Version (String) = {verStr}"); }
public static void Init(TestContext context) { _ = context; string absPath = TestHelper.GetProgramAbsolutePath(); BaseDir = Path.GetFullPath(Path.Combine(absPath, "..", "..", "..")); SampleDir = Path.Combine(BaseDir, "Samples"); string libPath = GetNativeLibPath(); XZInit.GlobalInit(libPath); }
public static void Init(TestContext context) { string absPath = TestHelper.GetProgramAbsolutePath(); BaseDir = Path.GetFullPath(Path.Combine(absPath, "..", "..", "..")); SampleDir = Path.Combine(BaseDir, "Samples"); string arch = null; switch (RuntimeInformation.OSArchitecture) { case Architecture.X86: arch = "x86"; break; case Architecture.X64: arch = "x64"; break; case Architecture.Arm: arch = "armhf"; break; case Architecture.Arm64: arch = "arm64"; break; } string libPath = null; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { libPath = Path.Combine(absPath, arch, "liblzma.dll"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { libPath = Path.Combine(absPath, arch, "liblzma.so"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { libPath = Path.Combine(absPath, arch, "liblzma.dylib"); } if (libPath == null || !File.Exists(libPath)) { throw new PlatformNotSupportedException(); } XZInit.GlobalInit(libPath); }
private void DecoderMemUsageTemplate(LzmaCompLevel level, bool extreme) { void PrintMemUsage(ulong usage) { char extremeChar = extreme ? 'e' : ' '; uint purePreset = (uint)level; Console.WriteLine($"Decoder Mem Usage (p{purePreset}{extremeChar}) = {usage / (1024 * 1024) + 1}MB ({usage}B)"); } ulong usage = XZInit.DecoderMemUsage(level, extreme); PrintMemUsage(usage); Assert.AreNotEqual(ulong.MaxValue, usage); }
public void PhysMem() { ulong physMem = XZInit.PhysMem(); Console.WriteLine($"Hardware Physical Memory = {physMem}"); }
private static void Initialize() { string arch = RuntimeInformation.OSArchitecture.ToString().ToLower(); string foundLibPath = string.Empty; string libPath; string rid; string libName; // Determine Platform (needed for proper Runtime ID) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { rid = $"win-{arch}"; libName = "liblzma.dll"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { rid = $"linux-{arch}"; libName = "liblzma.so"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { rid = $"osx-{arch}"; libName = "liblzma.dylib"; } else { // Unknown platform throw new PlatformNotSupportedException("Unknown runtime platform!"); } // Try to search for the lib in the working directory and the application binary directory foreach (var relPath in new List <string> { ".", AppDomain.CurrentDomain.BaseDirectory }) { // Try first the lib name directly libPath = Path.Combine(relPath, libName); if (System.IO.File.Exists(libPath)) { foundLibPath = libPath; break; } // Try the runtimes/RID/native location // This is the default location for netstandard native libs libPath = Path.Combine(relPath, "runtimes", rid, "native", libName); if (System.IO.File.Exists(libPath)) { foundLibPath = libPath; break; } } // Try the OS search path if nothing is found yet if (string.IsNullOrEmpty(foundLibPath)) { var values = Environment.GetEnvironmentVariable("PATH"); foreach (string path in values.Split(Path.PathSeparator)) { libPath = Path.Combine(path, libName); if (System.IO.File.Exists(libPath)) { foundLibPath = libPath; break; } } } if (string.IsNullOrEmpty(foundLibPath)) { throw new PlatformNotSupportedException($"Unable to find {libName}"); } // Initialize XZ library XZInit.GlobalInit(foundLibPath); }
public static void Uninitialize() { XZInit.GlobalCleanup(); }
public static void Cleanup() { XZInit.GlobalCleanup(); }