mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-24 00:00:05 +08:00
Merge commit '86cc97e55fe346502462284d2e636a2b3708163e' as 'Sources/OpenVPN3'
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(tests)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake;${CMAKE_MODULE_PATH}")
|
||||
include(findcoredeps)
|
||||
include(dlgoogletest)
|
||||
|
||||
# Extra includes/libraries that are currently only use by the core unit test
|
||||
FIND_PATH(LZO_INCLUDE_DIR NAMES lzo/lzo1x.h)
|
||||
FIND_LIBRARY(LZO_LIBRARIES NAMES lzo2)
|
||||
|
||||
if (LZO_INCLUDE_DIR AND LZO_LIBRARIES)
|
||||
list(APPEND CORE_TEST_DEFINES -DHAVE_LZO)
|
||||
list(APPEND EXTRA_LIBS ${LZO_LIBRARIES})
|
||||
list(APPEND EXTRA_INCLUDES ${LZO_INCLUDE_DIR})
|
||||
message("lzo found, running lzo compression tests")
|
||||
else ()
|
||||
message("lzo not found, skipping lzo compression tests")
|
||||
endif ()
|
||||
|
||||
set(SOURCES
|
||||
core_tests.cpp
|
||||
test_route_emulation.cpp
|
||||
test_log.cpp
|
||||
test_comp.cpp
|
||||
test_b64.cpp
|
||||
)
|
||||
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
list(APPEND SOURCES test_sitnl.cpp test_cpu_time.cpp)
|
||||
endif ()
|
||||
|
||||
|
||||
set(CORE_TEST_DEFINES
|
||||
-DOPENVPN_FORCE_TUN_NULL
|
||||
-DUNIT_TEST
|
||||
-DUNITTEST_SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\"
|
||||
)
|
||||
|
||||
add_executable(coreUnitTests ${SOURCES})
|
||||
|
||||
add_core_dependencies(coreUnitTests)
|
||||
target_link_libraries(coreUnitTests gtest_main ${EXTRA_LIBS})
|
||||
|
||||
target_compile_definitions(coreUnitTests PRIVATE ${CORE_TEST_DEFINES})
|
||||
target_include_directories(coreUnitTests PRIVATE ${EXTRA_INCLUDES})
|
||||
|
||||
add_test(NAME CoreTests COMMAND coreUnitTests)
|
||||
@@ -0,0 +1,3 @@
|
||||
To test and compare speed of the decomrpession algorithms define N_EXPAND to be more than 1 by either edition
|
||||
the test-comp.c or by add a -DN_EXPAND=1000 or -DN_COMPRESS=1000 for the compression speed in the CmakeLists
|
||||
and looks at the time the unit test take for the different combinations.
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,645 @@
|
||||
<head>
|
||||
<title>Compression Pointers</title>
|
||||
<META HTTP-EQUIV="Keywords" CONTENT="compression, compression, compression">
|
||||
</head>
|
||||
<body>
|
||||
<BODY BGCOLOR=#FFFFFF>
|
||||
|
||||
<center>
|
||||
<H1> Compression Pointers </h1>
|
||||
|
||||
|
||||
|
||||
</center>
|
||||
|
||||
<p>
|
||||
<a href="#Resources">Compression resources</a>, <a href="#Conferences">conferences</a>, and some <a href="#Research">research
|
||||
groups and companies</a>, are listed towards the end of this page. <p>
|
||||
|
||||
Use this <a href="form.html">handy form</a> to add something to this page, or to simply say you liked this page<i> <img src="new.gif">
|
||||
<p>
|
||||
|
||||
</i>
|
||||
|
||||
|
||||
|
||||
<p>
|
||||
|
||||
<h2>What's New?</h2><p>
|
||||
|
||||
|
||||
<a href="http://www.teaser.fr/~jlgailly/">Jean-loup Gailly</a> -- <i>Mr. gzip,
|
||||
PNG, CCR (1996-06-10)</i>
|
||||
<img src="new.gif">
|
||||
<br>
|
||||
|
||||
<a href="http://www.creative.net/~tristan/MPEG">MPEG Pointers and Resources</a>
|
||||
<img src="new.gif">
|
||||
<br>
|
||||
|
||||
<a href="http://www-isl.stanford.edu/~gray/">Robert M. Gray</a> -- <i>Signal
|
||||
compression, VQ, image quality evaluation (1996-04-22)</i><img src="new.gif">
|
||||
<br>
|
||||
|
||||
<a href="http://www-isl.stanford.edu/~gray/compression.html">Compression and
|
||||
Classification Group</a> -- <i>ISL,EE,Stanford (1996-04-22)</i><img src="new.gif">
|
||||
<br>
|
||||
|
||||
<a href="http://www-isl.stanford.edu/~gray/iii.html">Signal Processing
|
||||
and the International Information Infrastructure</a> -- <i>Web sites (1996-04-22)</i> <img src="new.gif">
|
||||
<br>
|
||||
|
||||
<a href="http://www.cs.sc.edu:80/~valenta/">Valenta, Vladimir</a> -- <i>(1996-04-22)</i>
|
||||
<br>
|
||||
|
||||
|
||||
<a href="http://patpwww.epfl.ch:80/~jordan/Subjects/Parallel/parallel.html">Jordan, Frederic</a> -- <i>Parallel Image Compression (1996-04-12)</i> <img src="new.gif">
|
||||
<br>
|
||||
<a href="http://www.garlic.com/biz/eotek">Electro-Optical Technologies, Inc.</a> -- <i>Consultant (1996-04-12)</i> <img src="new.gif">
|
||||
<br>
|
||||
<a href="http://quicktime.apple.com">quicktime.apple.com</a> -- <i>Quicktime site (1996-03-11)</i> <img src="new.gif">
|
||||
<br>
|
||||
<a href="http://www.chips.ibm.com/products/aldc/index.html">IBM Hardware</a> -- <i>Compression chips (1996-03-11)</i> <img src="new.gif">
|
||||
<br>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!---
|
||||
|
||||
<img src="new.gif"><i>Do you have, or know of, a research position where an image compression guru with a Ph.D. would feel at
|
||||
home? Let me know if you do...<a
|
||||
href="mailto:singlis@cs.waikato.ac.nz"><b>send me some email!</b></a>, or <a
|
||||
href="http://www.cs.waikato.ac.nz/~singlis/cv.html"><b>check out my
|
||||
c.v.</b>
|
||||
</a>
|
||||
</i>
|
||||
|
||||
-->
|
||||
|
||||
<p>
|
||||
|
||||
|
||||
<p>
|
||||
|
||||
|
||||
<h2><i>People</i></h2>
|
||||
<h2>A</h2>
|
||||
|
||||
<a href="http://quest.jpl.nasa.gov/Mark.Adler/">Adler, Mark</a> -- <i>Info-ZIP; Zip, UnZip, gzip and zlib co-author; PNG group</i>
|
||||
<p>
|
||||
|
||||
<h2>B</h2>
|
||||
|
||||
<a href="http://www.eese.qut.edu.au/~mbaker/">Baker, Matthew</a> -- <i>Region based video compression</i>
|
||||
<p>
|
||||
<a href="http://www.eecs.wsu.edu/~bamberg/">Bamberger, Roberto H.</a>
|
||||
<p>
|
||||
<a href="http://sutherland.eese.qut.edu.au/~dbell">Bell, Daniel</a> -- <i>Region based image compression</i>
|
||||
<p>
|
||||
<a href="http://www.cosc.canterbury.ac.nz/~tim">Bell, Tim</a> -- <i>compression, computer science for children, and computers and music.</i>
|
||||
<p>
|
||||
<a href="http://www.polytechnique.fr/poly/~bellard/">Bellard, Fabrice</a> -- <i>Author of LZEXE</I>
|
||||
<p>
|
||||
<a href="http://www.cevis.uni-bremen.de/~willy/">Berghorn, Willy </a>
|
||||
<p>
|
||||
<a href="http://www.best.com/~bhaskara">Bhaskaran, Vasudev</a> -- <i>Image and Video compression</i>
|
||||
<p>
|
||||
<a href="http://wwwvms.utexas.edu/~cbloom/index.html">Bloom, Charles</a> -- <i>text compression, LZ methods, PPM methods...</i>
|
||||
<p>
|
||||
<a href="http://www.ime.usp.br/~rbrito">Brito, Roger</a> -- <i>Arithmetic Coding, LZW, Text Compression</i>
|
||||
<p>
|
||||
<a href="http://www.engineering.usu.edu/ece/faculty/scottb.html">Budge, Scott E.</a> -- <i>medical/lossy image compression</i>
|
||||
<p>
|
||||
<a href="http://www.elec.uow.edu.au/people/staff/burnett/biography.html">Burnett, Ian</a> -- <i>Speech coding, prototype waveform techniques</I> <img src="new.gif">
|
||||
<p>
|
||||
|
||||
|
||||
<h2>C</h2>
|
||||
|
||||
<a href="http://gabor.eecs.berkeley.edu/~wychan/">Chan, Christopher</a> -- <i>universal lossy source coding, adaptive VQ</i>
|
||||
<p>
|
||||
<a href="http://www.compsci.com/~chao">Chao, Hong-yang</a> -- <I>Lightning strike image compressor </i>
|
||||
<p>
|
||||
<a href="http://monet.uwaterloo.ca:80/schao/">Chao, Stewart</a>
|
||||
<p>
|
||||
<a href="http://diana.ecs.soton.ac.uk/~pjc94r/">Cherriman, Peter</a>
|
||||
<p>
|
||||
<a href="http://www-video.eecs.berkeley.edu/erl/sccheung.html">Cheung, S.C.</a> -- <i>Scalable video compression algorithms (18th Feb 1996)</i> <img src="new.gif">
|
||||
<p>
|
||||
|
||||
<a href="http://etro.vub.ac.be/chchrist.html">Christopoulos, Charilaos</a> -- <i> Image and Video compression </i>
|
||||
<p>
|
||||
<a href="http://sipi.usc.edu/~chrysafi/">Chrysafis, Christos</a>
|
||||
<p>
|
||||
<a href="http://www.ee.gatech.edu/research/DSP/students/wchung/index.html">Chung, Wilson C.</a> -- <i>R-D image and video coding, subband/wavelet, filter banks</i>
|
||||
<p>
|
||||
<a href="mailto:aclark@hayes.com">Clark, Alan</a> -- <i>primary contact for V.42bis. Developed BTLZ variant of LZW</i>
|
||||
<p>
|
||||
<a href="http://www.cs.waikato.ac.nz/cs/Staff/jgc.html">Cleary, John</a> -- <i>PPM, PPM*, K*</i>
|
||||
<p>
|
||||
<a href="http://www.cs.brandeis.edu/dept/faculty/cohn/">Cohn, Martin</a>
|
||||
<p>
|
||||
|
||||
<a href="http://plg.uwaterloo.ca/~gvcormac">Cormack, Gordon V.</a> -- <I>DMC</i>
|
||||
<p>
|
||||
<a href="http://www.ee.duke.edu/~cec/index.html">Cramer, Chris</a> -- <i>neural network image compression</i>
|
||||
<p>
|
||||
|
||||
<h2>D</h2>
|
||||
<a href="http://www.cs.dartmouth.edu/~jmd/">Danskin, John</a> -- <i>Protocol compression, document compression (9th Feb 1996)</i>
|
||||
<p>
|
||||
<a href="http://www.cs.dartmouth.edu/~gdavis">Davis, Geoff</a> -- <i>wavelets, image compression, medical</i>
|
||||
<p>
|
||||
<a href="http://www-mddsp.enel.ucalgary.ca/People/adilger/">Dilger, Andreas</a> -- <i>fractal block coding of video sequences</i>
|
||||
<p>
|
||||
|
||||
|
||||
<h2>E</h2>
|
||||
<a href="http://info.cipic.ucdavis.edu/~estes/index.html">Estes, Robert</a>
|
||||
<p>
|
||||
|
||||
|
||||
|
||||
<h2>F</h2>
|
||||
<a href="http://inls.ucsd.edu/y/Fractals/">Fisher, Yuval</a> -- <i>Fractal Image Compression</i>
|
||||
<p>
|
||||
<a href="http://www.wmin.ac.uk/~ajoec1/homepage.html">Ford, Adrian</a> -- <i>Subjective and Objective Compression quality (5th Mar 1996)</i> <img src="new.gif">
|
||||
<p>
|
||||
|
||||
<h2>G</h2>
|
||||
<a href="http://www.teaser.fr/~jlgailly/">Jean-loup Gailly</a> --
|
||||
<i>Mr. gzip, PNG, CCR (1996-06-10)</i>
|
||||
<p>
|
||||
|
||||
<a href="http://www.ece.ucsb.edu/faculty/gersho/default.html">Gersho, Allen</a> -- <i>Vector Quantisation, Image Compression</i>
|
||||
<p>
|
||||
<a href="http://life.anu.edu.au/ci/vol1/goertzel.html">Goertzel, Ben</a>
|
||||
<p>
|
||||
<a href="http://info.lut.ac.uk/departments/el/research/sys/compression.html">Gooch, Mark</a> -- <i>High Performance Hardware Compression (7th Feb 1996)</i>
|
||||
<p>
|
||||
<a href="http://robotics.eecs.berkeley.edu/~vkgoyal/">Goyal, Vivek</a> -- <i>overcomplete representations, adaptive transform coding, VQ</i>
|
||||
<p>
|
||||
<a href="http://www-isl.stanford.edu/~gray/">Robert M. Gray</a> -- <i>Signal
|
||||
compression, VQ, image quality evaluation</i><img src="new.gif">
|
||||
<p>
|
||||
|
||||
<h2>H</h2>
|
||||
<a href="http://cork.informatik.uni-wuerzburg.de/mitarbeiter/ulli">Hafner, Ullrich</a> -- <i>WFA image compression</i>
|
||||
<p>
|
||||
<a href="http://www.ics.uci.edu/~dan/">Hirschberg, Dan</a> -- <i>algorithm theory, compression</i>
|
||||
<p>
|
||||
<a href="http://wolfpack.larc.nasa.gov/holland.html">Holland, Scott</a>
|
||||
<p>
|
||||
<a href="http://www.csc.uvic.ca/home/nigelh/nigelh.html">Horspool, R. Nigel</a> -- <i>text compression, ECG compression</i>
|
||||
|
||||
<h2>I</h2>
|
||||
<a href="http://www.cs.waikato.ac.nz/~singlis">Inglis, Stuart</a> -- <i>image compression, OCR, lossy/lossless document compression</I>
|
||||
<p>
|
||||
|
||||
<h2>J</h2>
|
||||
<a href="http://www.cs.uiowa.edu/~jones/compress/index.html">Jones, Douglas</a> -- <i>splay-tree based compression and encryption</i>
|
||||
<p>
|
||||
<a href="http://info.lut.ac.uk/departments/el/research/sys/compression.html">Jones, Simon</a> -- <i>Lossless compression, High Performance Hardware (7th Feb 1996) </i>
|
||||
<p>
|
||||
<a href="http://patpwww.epfl.ch:80/~jordan/Subjects/Parallel/parallel.html">Jordan, Frederic</a> -- <i>Parallel Image Compression (12th April 1996)</i> <img src="new.gif">
|
||||
<p>
|
||||
<a href="mailto:robjung@world.std.com">Jung, Robert K.</a> -- <i><a href="http://www.info.fundp.ac.be/~fta/arj.html">ARJ</a> </i>
|
||||
<p>
|
||||
<a href="http://www.cs.tu-berlin.de/~jutta/toast.html">jutta</a>
|
||||
<p>
|
||||
|
||||
|
||||
|
||||
<h2>K</h2>
|
||||
<a href="http://links.uwaterloo.ca">Kominek, John</a> -- <I>Fractal and spline based compression</i>
|
||||
<p>
|
||||
<a href="http://info.lut.ac.uk/departments/el/research/sys/elmk3.html">Kjelso, Morten</a> -- <i>Main memory compression, High performance hardware</i>
|
||||
<p>
|
||||
<a href="http://wwwcip.informatik.uni-erlangen.de/user/mskuhn">Kuhn, Markus</a> -- <i>JBIG implementation</i> <img src="new.gif">
|
||||
<p>
|
||||
<a href="http://sipi.usc.edu/faculty/Kuo.html">Kuo, C.-C. Jay</a>
|
||||
<p>
|
||||
<a href="http://kaarna.cc.jyu.fi:80/~kuru/">Kuru, Esa</a>
|
||||
<p>
|
||||
<a href="http://www.prz.tu-berlin.de:80/~teo/">Kyfonidis, Theodoros</a>
|
||||
<p>
|
||||
|
||||
<h2>L</h2>
|
||||
<a href="http://www.icsi.berkeley.edu/~lampart/">Lamparter, Bernd</a>
|
||||
<p>
|
||||
<a href="http://www.cse.ucsc.edu/cgi-bin/faculty?langdon">Langdon, Glen</a>
|
||||
<p>
|
||||
<a href="http://www.dna.lth.se/~jesper/">Larsson, Jesper</a> -- <i>algorithms and data structures, text compression</i> <img src="new.gif">
|
||||
<p>
|
||||
|
||||
|
||||
<h2>M</h2>
|
||||
<a href="http://glimpse.cs.arizona.edu:1994/udi.html">Manber, Udi</a>
|
||||
<p>
|
||||
<a href="http://www.elec.rma.ac.be/~jma/compression.html">Mangen, Jean-Michel</a> -- <i>image compression, wavelets, satellite</I>
|
||||
<p>
|
||||
<a href="http://www.cs.mu.oz.au/~alistair">Moffat, Alistair</a> -- <i>text and index compression, coding methods, information retrieval, document databases</i>
|
||||
<p>
|
||||
<a href="http://deskfish.cs.titech.ac.jp/squish/squish_index.html">Montgomery, Christopher</a> -- <i>OggSquish, audio compression</i>
|
||||
<p>
|
||||
<a href="mailto:umueller@amiga.physik.unizh.ch">Mueller, Urban Dominik</a> -- <i>XPK system</I>
|
||||
<p>
|
||||
<h2>N</h2>
|
||||
<a href="ftp://ai.toronto.edu/pub/radford/www/index.html">Neal, Radford</a>
|
||||
<p>
|
||||
<a href="http://www.cs.waikato.ac.nz/~cgn">Nevill-Manning, Craig</a>
|
||||
<p>
|
||||
<a href="http://phoenix.bath.ac.uk/jez/jez.html">Nicholls, Jeremy</a>
|
||||
<p>
|
||||
<a href="http://www.acti.com/matt/">Noah, Matt</a> -- <i>speech, ATC, ACELP and IMBE</i>
|
||||
<p>
|
||||
<a href="http://www.eecs.wsu.edu/~vnuri/">Nuri, Veyis</a> -- <i>wavelets, data compression, DSP (speech & image)</I>
|
||||
|
||||
<h2>O</h2>
|
||||
<a href="ftp://replicant.csci.unt.edu/pub/oleg/README.html">Oleg</a> -- <i>Lots of code</i>
|
||||
<p>
|
||||
<a href="http://sipi.usc.edu/faculty/Ortega/Ortega.html">Ortega, Antonio</a> -- <i>Video compression, Packet video, Adaptive quantization</i>
|
||||
<p>
|
||||
<a href="http://www.cs.dartmouth.edu:80/~cowen/">Owen, Charles</a>
|
||||
<p>
|
||||
|
||||
<h2>P</h2>
|
||||
<a
|
||||
href="http://www-mddsp.enel.ucalgary.ca/People/provine/compression.html">Provine,
|
||||
Joseph</a> -- <i>Model based coding</i>
|
||||
<p>
|
||||
|
||||
<h2>R</h2>
|
||||
<a href="http://monet.uwaterloo.ca/~john/btpc.html">Robinson, John</a> -- <i>Binary Tree Predictive Coding</i>
|
||||
<p>
|
||||
<a href="http://quest.jpl.nasa.gov/Info-ZIP/people/greg/">Roelofs, Greg</a> -- <i>Info-ZIP; primary UnZip author; PNG group</i>
|
||||
<p>
|
||||
<a href="http://www.ece.ucsb.edu/faculty/rose/default.html">Rose, Kenneth</a>
|
||||
<p>
|
||||
<a href="http://www.nettuno.it/fiera/telvox/telvox.htm">Russo, Roberto Maria</a> -- <I>Multiplatform Data Compression</i>
|
||||
<p>
|
||||
|
||||
<h2>S</h2>
|
||||
<a href="http://harc.edu:80/~schmidt/">Schmidt, Bill</a>
|
||||
<p>
|
||||
<a href="http://koa.ifa.hawaii.edu/~shaw/shaw.html">Shaw, Sandy C.</a>
|
||||
<p>
|
||||
<a href="http://www.comm.toronto.edu/~kamran/kamran.html">Sharifi, Kamran</a> -- <i>Video over ATM networks</i>
|
||||
<p>
|
||||
<a href="http://calypso.unl.edu/~sunil/">Shende, Sunil M.</a>
|
||||
<p>
|
||||
<a href="http://viewprint2.berkeley.edu/KleinLab/Amnon/Amnon.html">Silverstein, D. Amnon</a>
|
||||
<p>
|
||||
<a href="http://www-plateau.cs.berkeley.edu/people/smoot">Smoot, Steve</a> -- <i>MPEG</i>
|
||||
<p>
|
||||
<a href="http://www.cs.brandeis.edu/dept/faculty/storer/">Storer, James A.</a>
|
||||
<p>
|
||||
<a href="http://rice.ecs.soton.ac.uk/index.html">Streit, Jurgen</a> -- <i>Low bitrate coding</i>
|
||||
<p>
|
||||
<a href="http://www_nt.e-technik.uni-rostock.de/~ts/index.html">Strutz, Tilo</a> -- <i>Wavelet image compressor, demonstration execs</i> <img src="new.gif">
|
||||
<p>
|
||||
|
||||
|
||||
<h2>T</h2>
|
||||
<a href="http://zaphod.csci.unt.edu:80/~srt/">Tate, Steve</a>
|
||||
<p>
|
||||
<a href="http://www.cs.waikato.ac.nz/~wjt">Teahan, Bill</a> -- <i>PPM, PPM*, master of the Calgary Corpus</i>
|
||||
<p>
|
||||
<a href="http://lightning.eee.strath.ac.uk/~duncan/">Thomson, Duncan</a> -- <i>ECG compression with ANNs</i>
|
||||
<p>
|
||||
<a href="http://outside.gsfc.nasa.gov/GRSS/">Tilton, James C.</a>
|
||||
<p>
|
||||
<a href="http://www.uni-karlsruhe.de/~un55/">Tomczyk, Marek</a>
|
||||
<p>
|
||||
<a href="http://munkora.cs.mu.oz.au/~aht">Turpin, Andrew</a> -- <i>Prefix Codes</i>
|
||||
<p>
|
||||
|
||||
<h2>V</h2>
|
||||
<a href="http://gabor.eecs.berkeley.edu/~martin/">Vetterli, Martin</a> -- <i>wavelets, subband coding, video compression, computational complexity</i>
|
||||
<p>
|
||||
<a href="http://www.cs.duke.edu/~jsv/HomePage.html">Vitter, Jeff</a>
|
||||
<p>
|
||||
<a href="http://www.eee.strath.ac.uk/~stathis/home.html">Voukelatos, Stathis</a>
|
||||
<p>
|
||||
<a href="http://www.xs4all.nl/~aipnl">de Vries, Nico</a> -- <i>AIP-NL, UltraCompressor II development</i> <img src="new.gif">
|
||||
<p>
|
||||
|
||||
<h2>W</h2>
|
||||
|
||||
<a href="http://ipcl.ee.queensu.ca/wareham/wareham.html">Wareham, Paul</a> -- <i>Region-oriented video coding</I>
|
||||
<p>
|
||||
<a href="mailto://Wegs59@aol.com">Wegener, Al</a> -- <i>DSP, lossless audio compression and AC-2</i>
|
||||
<p>
|
||||
<a href="http://www-dsp.rice.edu:80/~weid/">Wei, Dong</a> -- <i>Wavelet compression</i>
|
||||
<p>
|
||||
<a href="http://www.rocksoft.com/~ross">Williams, Ross</a>
|
||||
<p>
|
||||
<a href="http://www.cs.waikato.ac.nz/~ihw">Witten, Ian</a> -- <i>PPM, mg, arithmetic coding</i>
|
||||
<p>
|
||||
<a href="http://www.sees.bangor.ac.uk/~gerry/sp_summary.html">Wolff, Gerry</a>
|
||||
<p>
|
||||
<a href="http://sipi.usc.edu/~wwoo/">Woo, Woon-Tack</a> -- <i>stereo image and video compression (12th Feb 1996)</i>
|
||||
<p>
|
||||
<a href="http://www.csd.uwo.ca/faculty/wu/">Wu, Xiaolin</a> -- <i>CALIC</i>
|
||||
<P>
|
||||
|
||||
|
||||
<h2>Z</h2>
|
||||
<a href="http://www.cs.rmit.edu.au/~jz">Zobel, Justin</a> -- <i>index compression, database compression</i>
|
||||
<p>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
|
||||
<a name="Conferences">
|
||||
|
||||
<h2><i>Conferences</i></h2>
|
||||
<a href="http://www.cs.brandeis.edu:80/~dcc/index.html"><b>Data Compression Conference (DCC), Snowbird, Utah, USA.</b></a><br>
|
||||
<p>
|
||||
|
||||
<a name="Resources">
|
||||
|
||||
<h2><i>Resources</i></h2>
|
||||
<dt>
|
||||
<i><b>Where to get answers...</b></i>
|
||||
<dd>
|
||||
<dd><a href="http://info.itu.ch/">International Telecommunication Union (ITU)</a> -- <i>standards documents (CCITT)</i>
|
||||
<br>
|
||||
<dd><a href="http://www.cis.ohio-state.edu/hypertext/faq/usenet/compression-faq/top.html">comp.compression -- Frequently Asked Questions</a> -- <i>Come here 1st!</i>
|
||||
<dd>
|
||||
<a href="http://www.cis.ohio-state.edu/hypertext/faq/usenet/jpeg-faq/faq.html">JPEG - Frequently Asked Questions</a>
|
||||
<dd>
|
||||
<a href="http://www.crs4.it/HTML/LUIGI/MPEG/mpegfaq.html">MPEG - Frequently Asked Questions</a>
|
||||
<dd>
|
||||
<a href="ftp://rtfm.mit.edu:/pub/usenet/news.answers/standards-faq">Standards - Frequenty Asked Questions</a>
|
||||
<dd>
|
||||
<a href="news:comp.compression.research">usenet newsgroup: comp.compression.research</a>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://www.mi.net/act/act.html">Archive Compression Test</a> -- <i>Summary of all archivers</i>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://dip1.ee.uct.ac.za/fractal.bib.html">Fractal compression bibliography</a> -- <i>bibtex file</i>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://goethe.ira.uka.de/edu/proseminar.html">LZ/Complexity Seminars</a> -- <i>(in German)</i>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://www.cs.waikato.ac.nz/~singlis/ratios.html">Comparitive Compression Ratios</a> -- <i>Sofar...B&W, Gray Scale, Text Compression</i>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://www.cs.ucl.ac.uk/mice/mpeggloss.html">VCN (Video, Compression, Networking)
|
||||
Glossary</a>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://www.cs.waikato.ac.nz/~nzdl/">Digital Library -- search for compression</a>
|
||||
<br>
|
||||
</dt>
|
||||
|
||||
<br>
|
||||
<dt>
|
||||
<i><b>Reports/Ph.D. Theses</b></i>
|
||||
<dd>
|
||||
<a href="http://www.cs.brown.edu/publications/techreports/reports/CS-93-28.html">Paul Howards Ph.D. thesis</a><br>
|
||||
<dd><i>The Design and Analysis of Efficient Lossless Data Compression Systems</i>
|
||||
<br>
|
||||
</dt>
|
||||
|
||||
|
||||
|
||||
<br>
|
||||
<dt>
|
||||
<i><b>Source code</b></i>
|
||||
<dd>
|
||||
<a href="ftp://munnari.oz.au/pub/arith_coder">Arithmetic coding routines</a>
|
||||
<dd><i>        (from Moffat, Neal and Witten, Proc. DCC, April 1995)</i>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="ftp://ftp.cpsc.ucalgary.ca/pub/projects/ar.cod">CACM Arithmetic coding package</a>
|
||||
<dd><i>        (Witten, Neal and Cleary, CACM 30:520-541, June 1987)</i>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="ftp://nic.funet.fi/pub/graphics/misc/test-images/jbig.tar.gz">JBIG Source code</a> <i>Includes a Q-coder</i>
|
||||
<br>
|
||||
<dd><a href="http://wwwcip.informatik.uni-erlangen.de/user/mskuhn">Markus Kuhn's JBIG implementation</a>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="ftp://media-lab.media.mit.edu/pub/k-arith-code/">k-arithmetic coder</a>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="ftp://garbo.uwasa.fi/pc/programming/lds_11.zip">Lossless Data Compression toolkit 1.1</a>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://www.cs.uiowa.edu/~jones/compress/index.html">Splay Trees Code</a> -- <i>by Douglas W. Jones</i>
|
||||
<br>
|
||||
<dd><a href="ftp://ftp.cl.cam.ac.uk/users/djw3">Block compression code</a> -- <i>Excellent text compressor</i>
|
||||
<br>
|
||||
|
||||
</dt>
|
||||
|
||||
<br>
|
||||
<dt>
|
||||
<i><b>Test Files</b></i>
|
||||
<dd>
|
||||
<a href="ftp://nic.funet.fi/pub/graphics/misc/test-images/">Test Images</a> -- <i>CCITT images (pbm), Lena etc. (Sun raster)</i>
|
||||
<br>
|
||||
<dd>
|
||||
Stockholm test images -- <i>You have to buy a CDROM, thats all I know! :-(</i>
|
||||
<dd>         mail me at <a href="mailto:singlis@cs.waikato.ac.nz">singlis@cs.waikato.ac.nz</a> if you know anything about them.
|
||||
<br>
|
||||
<dd>
|
||||
<a href="ftp://ftp.cpsc.ucalgary.ca/pub/projects/text.compression.corpus/">Calgary Text Compression Corpus</a><i> (Text Compression, Bell, Cleary and Witten, 1990)</i>
|
||||
<br>
|
||||
</dt>
|
||||
|
||||
<br>
|
||||
|
||||
<a name="Research">
|
||||
|
||||
|
||||
<h2><i>Research Projects, Standards & Companies</i></h2>
|
||||
|
||||
<p>
|
||||
<dt>
|
||||
<i><b>Research/Free software Groups</b></i>
|
||||
<dd><a href="http://www-isl.stanford.edu/~gray/compression.html">Compression and
|
||||
Classification Group</a> -- <i>ISL,EE,Stanford (22th April 1996)</i><img src="new.gif">
|
||||
|
||||
<dd><a href="http://www.bonzi.com">Voice email</a> -- <i>Lossless audio compression (18th Feb 1996)</i>
|
||||
|
||||
|
||||
<dd><a href="http://www.garlic.com/biz/eotek">Electro-Optical Technologies, Inc.</a> -- <i>Consultant (12th April 1996)</i> <img src="new.gif">
|
||||
|
||||
<dd><a href="http://quicktime.apple.com">quicktime.apple.com</a> -- <i>Quicktime site (11th Mar 1996)</i>
|
||||
|
||||
<dd><a href="http://www.atinternet.fr/image/">IMAGE etc.</a> -- <i>Commercial image compression software (Fractals/Wavelets) (29th Feb 1996)</i> <img src="new.gif">
|
||||
|
||||
<dd><a href="http://re7alpha.epm.ornl.gov/CcmDemo/">NCAR CCM Compression and Visualisation</a> -- <i>(18th Feb 1996)</i> <img src="new.gif">
|
||||
<br>
|
||||
<dd><a href="http://ipl.rpi.edu/SPIHT/">SPIHT</a> -- <I>Wavelet Natural Image Compressor (12th Feb 1996)</i> <img src="new.gif">
|
||||
<br>
|
||||
<dd><a href="http://info.lut.ac.uk/departments/el/research/sys/compression.html">Real-Time Lossless Compression Systems</a> -- <i>Loughborough University</i> <img src="new.gif">
|
||||
<br>
|
||||
<dd><a href="http://saigon.ece.wisc.edu/~waveweb/QMF.html">Web site for Multirate Signal Processing</a> -- <i>University of Wisconsin, Madison</i>
|
||||
<br>
|
||||
<dd><a href="http://quest.jpl.nasa.gov/Info-ZIP/">Info-ZIP</a> -- <i>free,
|
||||
portable Zip and UnZip utilities</i>
|
||||
<br>
|
||||
<dd><a href="http://cesdis.gsfc.nasa.gov/">CEDIS</a> -- <i>NASA, Maryland, Image/data compression</i>
|
||||
<br>
|
||||
<dd><a href="http://www.c3.lanl.gov/~brislawn/ftp.html">CIC-3 Image Compression</a> -- <i>FBI Fingerprints</i>
|
||||
<br>
|
||||
<dd><a href="http://rainbow.ece.ucsb.edu/scl.html">Signal Compression Lab at UCSB</a>
|
||||
<br>
|
||||
<dd><a href="http://isdl.ee.washington.edu/COMPRESSION/homepage.html">University of
|
||||
Washington compression lab</a> -- <I>VQ, Wavelets, Shlomo</i>
|
||||
<br>
|
||||
</dt>
|
||||
|
||||
|
||||
<p>
|
||||
<dt>
|
||||
<i><b>Snippets</b></i>
|
||||
<dd><a href="http://www-isl.stanford.edu/~gray/iii.html">Signal Processing
|
||||
and the International Information Infrastructure</a> -- <i>Web sites (22th April 1996)</i> <img src="new.gif">
|
||||
<dd><a href="http://www.scu.edu.au/ausweb95/papers/management/vanzyl/">Increasing Web bandwith</a> -- <i>comparing GIF, JPEG, Fractal compression</i>
|
||||
<br>
|
||||
<dd><a href="http://www.yahoo.com/Art/Computer_Generated/Fractals">Fractal Links on Yahoo</a>
|
||||
<br>
|
||||
<dd><a href="http://www.ddj.com/old/ddjw001d.htm">Digital Speech Compression GSM 06.10 RPE-LTP</a> -- <i>DDJ</i>
|
||||
<br>
|
||||
<dd><a href="http://www.crc.ricoh.com/CREW/">CREW</a> -- <i>Continuous tone loss(y/less) wavelet compression</i>
|
||||
<br>
|
||||
<dd><a href="ftp://ftp.csd.uwo.ca/pub/from_wu/">CALIC -- Context-based adaptive lossless image compressor</a>
|
||||
<br>
|
||||
<dd><a href="http://www-plateau.cs.berkeley.edu/mpeg/index.html">Berkeley MPEG</a> -- <i>MPEG tools</i>
|
||||
<br>
|
||||
<dd><a href="http://www.creative.net/~tristan/MPEG">MPEG Pointers and Resources</a>
|
||||
<BR>
|
||||
</dt>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<p>
|
||||
<dt>
|
||||
<i><b>Wavelets</b></i>
|
||||
<dd>
|
||||
<a href="http://www.cis.upenn.edu/~eero/epic.html">
|
||||
EPIC (Efficient Pyramid Image Coder)</a> -- <i>by Eero Simoncelli</i>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="mailto://72234.2617@compuserve.com">Tucker, Michael</a> -- <i>FASTWAVE, audio/image compression</i>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://www.harc.edu">HARC</a> -- <i>Lossy Wavelet Compression technology</i>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://gabor.eecs.berkeley.edu/">UC Berkeley Wavelet Group</a>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://www.c3.lanl.gov/~cjhamil/Wavelets/main.html">Khoros Wavetlet and Compression Toolbox</a>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://arabigo.math.scarolina.edu:80/~wavelet/">The Wavelet Digest</a>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://jazz.rice.edu/publications.html">Rice DSP Publications Archive</a> -- <i>Wavelets, Time Frequency/Scale</i>
|
||||
<br>
|
||||
</dt>
|
||||
|
||||
<p>
|
||||
<dt>
|
||||
<i><b>Fractals</b></i>
|
||||
<dd>
|
||||
<a href="http://inls.ucsd.edu/y/Fractals/">Fractal Image Compression</a> -- <i>Software, Pointers, Conferences</i>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://www.fractal.com/">Fractal Design Corporation</a>
|
||||
<br>
|
||||
<dd>
|
||||
<a href="http://www.webcom.com/~verrando/university/ifs.html">New Fractal Image Compression program</a>
|
||||
<br>
|
||||
</dt>
|
||||
|
||||
<p>
|
||||
<dt>
|
||||
<i><b>Companies</b></i>
|
||||
<dd><a href="http://www.chips.ibm.com/products/aldc/index.html">IBM Hardware</a> -- <i>Compression chips (11th Mar 1996)</i> <img src="new.gif">
|
||||
|
||||
<dd><a href="http://www.summus.com">Summus Wavelet Technology</a> -- <i>Wavelet image and video compressors (11th Mar 1996)</i> <img src="new.gif">
|
||||
<dd><a href="http://www.mitsubishi.co.jp/jp/fractal/fractal.html">Fractal Image Compression</a> -- <I>Mitsubishi (18th Feb 1996)</i> <img src="new.gif">
|
||||
|
||||
<dd><a href="http://www.terran-int.com/">Terran Interactive</a> -- <i>Video compression for the Mac (1st Feb 1996)</i> <img src="new.gif">
|
||||
<br>
|
||||
|
||||
<dd><a href="http://darvision.kaist.ac.kr/dvmpeg.html">DV Mpeg</a> -- <i>Windows drivers (18th Feb 1996)</I> <img src="new.gif">
|
||||
<br>
|
||||
|
||||
<dd><a href="http://www.crawford.com/cs/welcome.html">Crawford Compression Services</a> -- <i>MPEG post-production (18th Feb 1996)</i> <img src="new.gif">
|
||||
<br>
|
||||
|
||||
<dd><a href="http://www.shore.net/~ict">Intelligent Compression Technologies</a> <i>(18th Feb 1996)</i> <img src="new.gif">
|
||||
<br>
|
||||
|
||||
<dd><a href="http://www.jpg.com">Pegasus Imaging</a> -- <i>Compression software/dev. kits (12th Feb 1996)</i> <img src="new.gif">
|
||||
<br>
|
||||
<dd><a href="http://www.aladdinsys.com/">Aladdin Systems</a> -- <i>StuffIt compression products</i>
|
||||
<br>
|
||||
<dd><a href="http://www.stac.com/">Stac Electronics</a>
|
||||
<br>
|
||||
<dd><a href="http://www.ccinet.ab.ca/dcp.html">DCP Research</a> -- <i>Hardware solutions</i>
|
||||
<br>
|
||||
<dd><a href="http://www.aware.com/product_info/compression_overview.html">Aware Inc.</a> -- <i>Specialised compression company</i>
|
||||
<br>
|
||||
<dd><a href="http://www.inria.fr/rodeo/ivs.html">IVS - INRIA Videoconferencing System</a>
|
||||
<br>
|
||||
<dd><a href="http://sp25.ianus.cineca.it/telvox/telvoxen.htm">Telvox Teleinformatica</a> -- <i>Multiplatform Data Compressor</i>
|
||||
<br>
|
||||
<dd><a href="http://www.compression.com">Compression Technologies,
|
||||
Inc</a> -- <i>Canada</i>
|
||||
<br>
|
||||
<dd><a href="http://www.optivision.com/">Optivision</a> -- <i>MPEG</i>
|
||||
<br>
|
||||
<dd><a href="http://www.pkware.com/">PKWARE</a> -- <i>Makers of PKZIP</i>
|
||||
<br>
|
||||
<dd><a href="http://www.infoanalytic.com/tayson/index.html">Multimedia Imaging Services</a>
|
||||
<br>
|
||||
</dt>
|
||||
|
||||
<p>
|
||||
<dt>
|
||||
<i><b>Audio compression</b></i>
|
||||
<dd><a href="http://www.iis.fhg.de/departs/amm/index.html"> Fraunhofer Institut für Integrierte Schaltungen</a>
|
||||
<br>
|
||||
<dd><a href="http://svr-www.eng.cam.ac.uk/~ajr/speechCoding.html">Shorten</a>
|
||||
<br>
|
||||
<dd><a href="http://www.ddj.com/old/ddjw001d.htm">digital speech compression</a>
|
||||
<br>
|
||||
<dd><a href="http://www.cs.tu-berlin.de/~phade/audiowww.html">Audio compression references</a>
|
||||
<br>
|
||||
<dd><a href="http://www.fourmilab.ch/speakfree/windows/doc/compress.html">SpeakFreely - compression</a>
|
||||
<br>
|
||||
<dd><a href="http://www.fourmilab.ch/speakfree/windows/speak_freely.html#contents">SpeakFreely - Contents</a>
|
||||
<br>
|
||||
@@ -0,0 +1,431 @@
|
||||
#ifndef lint
|
||||
static char Rcs_Id[] =
|
||||
"$Id: fields.c,v 1.7 1994/01/06 05:26:37 geoff Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* $Log: fields.c,v $
|
||||
* Revision 1.7 1994/01/06 05:26:37 geoff
|
||||
* Get rid of all references to System V string routines, for portability
|
||||
* (sigh).
|
||||
*
|
||||
* Revision 1.6 1994/01/05 20:13:43 geoff
|
||||
* Add the maxf parameter
|
||||
*
|
||||
* Revision 1.5 1994/01/04 02:40:21 geoff
|
||||
* Make the increments settable (field_line_inc and field_field_inc).
|
||||
* Add support for the FLD_NOSHRINK flag.
|
||||
*
|
||||
* Revision 1.4 1993/09/27 17:48:02 geoff
|
||||
* Fix some lint complaints and some parenthesization errors.
|
||||
*
|
||||
* Revision 1.3 1993/09/09 01:11:11 geoff
|
||||
* Add a return value to fieldwrite. Add support for backquotes and for
|
||||
* unstripped backslashes.
|
||||
*
|
||||
* Revision 1.2 1993/08/26 00:02:50 geoff
|
||||
* Fix a stupid null-pointer bug
|
||||
*
|
||||
* Revision 1.1 1993/08/25 21:32:05 geoff
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "config.h"
|
||||
#include "fields.h"
|
||||
|
||||
field_t * fieldread P ((FILE * file, char * delims,
|
||||
int flags, int maxf));
|
||||
/* Read a line with fields from a file */
|
||||
field_t * fieldmake P ((char * line, int allocated, char * delims,
|
||||
int flags, int maxf));
|
||||
/* Make a field structure from a line */
|
||||
static field_t * fieldparse P ((field_t * fieldp, char * line, char * delims,
|
||||
int flags, int maxf));
|
||||
/* Parse the fields in a line */
|
||||
static int fieldbackch P ((char * str, char ** out, int strip));
|
||||
/* Process backslash sequences */
|
||||
int fieldwrite P ((FILE * file, field_t * fieldp, int delim));
|
||||
/* Write a line with fields to a file */
|
||||
void fieldfree P ((field_t * fieldp));
|
||||
/* Free a field returned by fieldread */
|
||||
|
||||
unsigned int field_field_inc = 20; /* Increment to increase # fields by */
|
||||
unsigned int field_line_inc = 512; /* Incr to increase line length by */
|
||||
|
||||
#ifndef USG
|
||||
#define strchr index
|
||||
#endif /* USG */
|
||||
|
||||
extern void free ();
|
||||
extern char * malloc ();
|
||||
extern char * realloc ();
|
||||
extern char * strchr ();
|
||||
extern int strlen ();
|
||||
|
||||
/*
|
||||
* Read one line of the given file into a buffer, break it up into
|
||||
* fields, and return them to the caller. The field_t structure
|
||||
* returned must eventually be freed with fieldfree.
|
||||
*/
|
||||
field_t * fieldread (file, delims, flags, maxf)
|
||||
FILE * file; /* File to read lines from */
|
||||
char * delims; /* Characters to use for field delimiters */
|
||||
int flags; /* Option flags; see fields.h */
|
||||
int maxf; /* Maximum number of fields to parse */
|
||||
{
|
||||
register char * linebuf; /* Buffer to hold the line read in */
|
||||
int linemax; /* Maximum line buffer size */
|
||||
int linesize; /* Current line buffer size */
|
||||
|
||||
linebuf = (char *) malloc (field_line_inc);
|
||||
if (linebuf == NULL)
|
||||
return NULL;
|
||||
linemax = field_line_inc;
|
||||
linesize = 0;
|
||||
/*
|
||||
* Read in the line.
|
||||
*/
|
||||
while (fgets (&linebuf[linesize], linemax - linesize, file)
|
||||
!= NULL)
|
||||
{
|
||||
linesize += strlen (&linebuf[linesize]);
|
||||
if (linebuf[linesize - 1] == '\n')
|
||||
break;
|
||||
else
|
||||
{
|
||||
linemax += field_line_inc;
|
||||
linebuf = (char *) realloc (linebuf, linemax);
|
||||
if (linebuf == NULL)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (linesize == 0)
|
||||
{
|
||||
free (linebuf);
|
||||
return NULL;
|
||||
}
|
||||
return fieldmake (linebuf, 1, delims, flags, maxf);
|
||||
}
|
||||
|
||||
field_t * fieldmake (line, allocated, delims, flags, maxf)
|
||||
char * line; /* Line to make into a field structure */
|
||||
int allocated; /* NZ if line allocated with malloc */
|
||||
char * delims; /* Characters to use for field delimiters */
|
||||
int flags; /* Option flags; see fields.h */
|
||||
int maxf; /* Maximum number of fields to parse */
|
||||
{
|
||||
register field_t * fieldp; /* Structure describing the fields */
|
||||
int linesize; /* Current line buffer size */
|
||||
|
||||
fieldp = (field_t *) malloc (sizeof (field_t));
|
||||
if (fieldp == NULL)
|
||||
return NULL;
|
||||
fieldp->nfields = 0;
|
||||
fieldp->linebuf = allocated ? line : NULL;
|
||||
fieldp->fields = NULL;
|
||||
fieldp->hadnl = 0;
|
||||
linesize = strlen (line);
|
||||
if (line[linesize - 1] == '\n')
|
||||
{
|
||||
line[--linesize] = '\0';
|
||||
fieldp->hadnl = 1;
|
||||
}
|
||||
/*
|
||||
* Shrink the line buffer if necessary.
|
||||
*/
|
||||
if (allocated && (flags & FLD_NOSHRINK) == 0)
|
||||
{
|
||||
line = fieldp->linebuf =
|
||||
(char *) realloc (fieldp->linebuf, linesize + 1);
|
||||
if (fieldp->linebuf == NULL)
|
||||
{
|
||||
fieldfree (fieldp);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return fieldparse (fieldp, line, delims, flags, maxf);
|
||||
}
|
||||
|
||||
static field_t * fieldparse (fieldp, line, delims, flags, maxf)
|
||||
register field_t * fieldp; /* Field structure to parse into */
|
||||
register char * line; /* Line to be parsed */
|
||||
char * delims; /* Characters to use for field delimiters */
|
||||
int flags; /* Option flags; see fields.h */
|
||||
int maxf; /* Maximum number of fields to parse */
|
||||
{
|
||||
int fieldmax; /* Max size of fields array */
|
||||
char * lineout; /* Where to store xlated char in line */
|
||||
char quote; /* Quote character in use */
|
||||
|
||||
fieldp->nfields = 0;
|
||||
fieldmax =
|
||||
(maxf != 0 && maxf < field_field_inc) ? maxf + 2 : field_field_inc;
|
||||
fieldp->fields = (char **) malloc (fieldmax * sizeof (char *));
|
||||
if (fieldp->fields == NULL)
|
||||
{
|
||||
fieldfree (fieldp);
|
||||
return NULL;
|
||||
}
|
||||
if ((flags
|
||||
& (FLD_SHQUOTES | FLD_SNGLQUOTES | FLD_BACKQUOTES | FLD_DBLQUOTES))
|
||||
== FLD_SHQUOTES)
|
||||
flags |= FLD_SNGLQUOTES | FLD_BACKQUOTES | FLD_DBLQUOTES;
|
||||
while (1)
|
||||
{
|
||||
if (flags & FLD_RUNS)
|
||||
{
|
||||
while (*line != '\0' && strchr (delims, *line) != NULL)
|
||||
line++; /* Skip runs of delimiters */
|
||||
if (*line == '\0')
|
||||
break;
|
||||
}
|
||||
fieldp->fields[fieldp->nfields] = lineout = line;
|
||||
/*
|
||||
* Skip to the next delimiter. At the end of skipping, "line" will
|
||||
* point to either a delimiter or a null byte.
|
||||
*/
|
||||
if (flags
|
||||
& (FLD_SHQUOTES | FLD_SNGLQUOTES | FLD_BACKQUOTES
|
||||
| FLD_DBLQUOTES | FLD_BACKSLASH))
|
||||
{
|
||||
while (*line != '\0')
|
||||
{
|
||||
if (strchr (delims, *line) != NULL)
|
||||
break;
|
||||
else if (((flags & FLD_SNGLQUOTES) && *line == '\'')
|
||||
|| ((flags & FLD_BACKQUOTES) && *line == '`')
|
||||
|| ((flags & FLD_DBLQUOTES) && *line == '"'))
|
||||
{
|
||||
if ((flags & FLD_SHQUOTES) == 0
|
||||
&& line != fieldp->fields[fieldp->nfields])
|
||||
quote = '\0';
|
||||
else
|
||||
quote = *line;
|
||||
}
|
||||
else
|
||||
quote = '\0';
|
||||
if (quote == '\0')
|
||||
{
|
||||
if (*line == '\\' && (flags & FLD_BACKSLASH))
|
||||
{
|
||||
line++;
|
||||
if (*line == '\0')
|
||||
break;
|
||||
line += fieldbackch (line, &lineout,
|
||||
flags & FLD_STRIPQUOTES);
|
||||
}
|
||||
else
|
||||
*lineout++ = *line++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Process quoted string */
|
||||
if ((flags & FLD_STRIPQUOTES) == 0)
|
||||
*lineout++ = quote;
|
||||
++line;
|
||||
while (*line != '\0')
|
||||
{
|
||||
if (*line == quote)
|
||||
{
|
||||
if ((flags & FLD_STRIPQUOTES) == 0)
|
||||
*lineout++ = quote;
|
||||
line++; /* Go on past quote */
|
||||
if ((flags & FLD_SHQUOTES) == 0)
|
||||
{
|
||||
while (*line != '\0'
|
||||
&& strchr (delims, *line) == NULL)
|
||||
line++; /* Skip to delimiter */
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (*line == '\\')
|
||||
{
|
||||
if (flags & FLD_BACKSLASH)
|
||||
{
|
||||
line++;
|
||||
if (*line == '\0')
|
||||
break;
|
||||
else
|
||||
line += fieldbackch (line, &lineout,
|
||||
flags & FLD_STRIPQUOTES);
|
||||
}
|
||||
else
|
||||
{
|
||||
*lineout++ = '\\';
|
||||
if (*++line == '\0')
|
||||
break;
|
||||
*lineout++ = *line;
|
||||
}
|
||||
}
|
||||
else
|
||||
*lineout++ = *line++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (*line != '\0' && strchr (delims, *line) == NULL)
|
||||
line++; /* Skip to delimiter */
|
||||
lineout = line;
|
||||
}
|
||||
fieldp->nfields++;
|
||||
if (*line++ == '\0')
|
||||
break;
|
||||
if (maxf != 0 && fieldp->nfields > maxf)
|
||||
break;
|
||||
*lineout = '\0';
|
||||
if (fieldp->nfields >= fieldmax)
|
||||
{
|
||||
fieldmax += field_field_inc;
|
||||
fieldp->fields =
|
||||
(char **) realloc (fieldp->fields, fieldmax * sizeof (char *));
|
||||
if (fieldp->fields == NULL)
|
||||
{
|
||||
fieldfree (fieldp);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Shrink the field pointers and return the field structure.
|
||||
*/
|
||||
if ((flags & FLD_NOSHRINK) == 0 && fieldp->nfields >= fieldmax)
|
||||
{
|
||||
fieldp->fields = (char **) realloc (fieldp->fields,
|
||||
(fieldp->nfields + 1) * sizeof (char *));
|
||||
if (fieldp->fields == NULL)
|
||||
{
|
||||
fieldfree (fieldp);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
fieldp->fields[fieldp->nfields] = NULL;
|
||||
return fieldp;
|
||||
}
|
||||
|
||||
static int fieldbackch (str, out, strip)
|
||||
register char * str; /* First char of backslash sequence */
|
||||
register char ** out; /* Where to store result */
|
||||
int strip; /* NZ to convert the sequence */
|
||||
{
|
||||
register int ch; /* Character being developed */
|
||||
char * origstr; /* Original value of str */
|
||||
|
||||
if (!strip)
|
||||
{
|
||||
*(*out)++ = '\\';
|
||||
if (*str != 'x' && *str != 'X' && (*str < '0' || *str > '7'))
|
||||
{
|
||||
*(*out)++ = *str;
|
||||
return *str != '\0';
|
||||
}
|
||||
}
|
||||
switch (*str)
|
||||
{
|
||||
case '\0':
|
||||
*(*out)++ = '\0';
|
||||
return 0;
|
||||
case 'a':
|
||||
*(*out)++ = '\007';
|
||||
return 1;
|
||||
case 'b':
|
||||
*(*out)++ = '\b';
|
||||
return 1;
|
||||
case 'f':
|
||||
*(*out)++ = '\f';
|
||||
return 1;
|
||||
case 'n':
|
||||
*(*out)++ = '\n';
|
||||
return 1;
|
||||
case 'r':
|
||||
*(*out)++ = '\r';
|
||||
return 1;
|
||||
case 'v':
|
||||
*(*out)++ = '\v';
|
||||
return 1;
|
||||
case 'X':
|
||||
case 'x':
|
||||
/* Hexadecimal sequence */
|
||||
origstr = str++;
|
||||
ch = 0;
|
||||
if (*str >= '0' && *str <= '9')
|
||||
ch = *str++ - '0';
|
||||
else if (*str >= 'a' && *str <= 'f')
|
||||
ch = *str++ - 'a' + 0xa;
|
||||
else if (*str >= 'A' && *str <= 'F')
|
||||
ch = *str++ - 'A' + 0xa;
|
||||
if (*str >= '0' && *str <= '9')
|
||||
ch = (ch << 4) | (*str++ - '0');
|
||||
else if (*str >= 'a' && *str <= 'f')
|
||||
ch = (ch << 4) | (*str++ - 'a' + 0xa);
|
||||
else if (*str >= 'A' && *str <= 'F')
|
||||
ch = (ch << 4) | (*str++ - 'A' + 0xa);
|
||||
break;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
/* Octal sequence */
|
||||
origstr = str;
|
||||
ch = *str++ - '0';
|
||||
if (*str >= '0' && *str <= '7')
|
||||
ch = (ch << 3) | (*str++ - '0');
|
||||
if (*str >= '0' && *str <= '7')
|
||||
ch = (ch << 3) | (*str++ - '0');
|
||||
break;
|
||||
default:
|
||||
*(*out)++ = *str;
|
||||
return 1;
|
||||
}
|
||||
if (strip)
|
||||
{
|
||||
*(*out)++ = ch;
|
||||
return str - origstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ch = 0; origstr < str; ch++)
|
||||
*(*out)++ = *origstr++;
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
|
||||
int fieldwrite (file, fieldp, delim)
|
||||
FILE * file; /* File to write to */
|
||||
register field_t * fieldp; /* Field structure to write */
|
||||
int delim; /* Delimiter to place between fields */
|
||||
{
|
||||
int error; /* NZ if an error occurs */
|
||||
register int fieldno; /* Number of field being written */
|
||||
|
||||
error = 0;
|
||||
for (fieldno = 0; fieldno < fieldp->nfields; fieldno++)
|
||||
{
|
||||
if (fieldno != 0)
|
||||
error |= putc (delim, file) == EOF;
|
||||
error |= fputs (fieldp->fields[fieldno], file) == EOF;
|
||||
}
|
||||
if (fieldp->hadnl)
|
||||
error |= putc ('\n', file) == EOF;
|
||||
return error;
|
||||
}
|
||||
|
||||
void fieldfree (fieldp)
|
||||
register field_t * fieldp; /* Field structure to free */
|
||||
{
|
||||
|
||||
if (fieldp == NULL)
|
||||
return;
|
||||
if (fieldp->linebuf != NULL)
|
||||
free ((char *) fieldp->linebuf);
|
||||
if (fieldp->fields != NULL)
|
||||
free ((char *) fieldp->fields);
|
||||
free ((char *) fieldp);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,94 @@
|
||||
;;; -*- Mode: Lisp; Syntax: Common-Lisp; -*-
|
||||
|
||||
(define-language
|
||||
:grammar
|
||||
'(((S $any) -> (S1 $any))
|
||||
((S (Compound $s1 $s2)) -> (S1 $s1) (Conjunction) (S1 $s2))
|
||||
|
||||
((S1 (Statement $v)) -> (NP $subj) (VP $subj $tense $v))
|
||||
((S1 (Acknowledge $a)) -> (Acknowledge $a))
|
||||
((S1 (Command $v)) -> (VP Self present $v))
|
||||
((S1 (Question $v)) -> (Aux $tense) (NP $subj) (VP $subj $tense $v))
|
||||
((S1 (Question $v)) -> (Be $tense) (NP $subj) (Be-Arg $subj $tense $v))
|
||||
|
||||
((Be-Arg $subj $tense (Occur $tense (loc $subj $loc))) ->
|
||||
(Loc-Adjunct $tense (loc $subj $loc)))
|
||||
|
||||
((VP $subj $tense (Occur $tense $v)) -> (VP1 $subj $tense $v))
|
||||
((VP $subj $tense (Occur $tense $v)) -> (Aux $tense)(VP1 $subj present $v))
|
||||
|
||||
((VP1 $subj $tense $v) -> (VP2 $subj $tense $v) (Adjunct? $v))
|
||||
|
||||
((VP2 $subj $tense ($rel $subj $loc)) ->
|
||||
(Verb/in $rel $tense))
|
||||
((VP2 $subj $tense ($rel $subj $loc $obj)) ->
|
||||
(Verb/tr $rel $tense) (NP $obj))
|
||||
((VP2 $subj $tense ($rel $subj $loc $obj $obj2)) ->
|
||||
(Verb/di $rel $tense) (NP $obj) (NP $obj2))
|
||||
((VP2 $subj $tense (loc $subj $loc)) ->
|
||||
(Be $tense) (Loc-Adjunct $tense (loc $subj $loc)))
|
||||
|
||||
((NP $n) -> (Pronoun $n))
|
||||
((NP $n) -> (Article) (Noun $n))
|
||||
((NP $n) -> (Noun $n))
|
||||
((NP ($x $y)) -> (Number $x) (Number $y))
|
||||
|
||||
((PP ($prep $n)) -> (Prep $prep) (NP $n))
|
||||
((Adjunct? $v) ->)
|
||||
((Adjunct? $v) -> (Loc-Adjunct $tense $v))
|
||||
#+Allegro ((Loc-Adjunct $tense ($rel $subj $loc @rest)) -> (PP $loc))
|
||||
#+Allegro ((Loc-Adjunct $tense ($rel $subj $loc @rest)) -> (Adjunct $loc))
|
||||
#+Lucid ((Loc-Adjunct $tense ($rel $subj $loc . $rest)) -> (PP $loc))
|
||||
#+Lucid ((Loc-Adjunct $tense ($rel $subj $loc . $rest)) -> (Adjunct $loc))
|
||||
|
||||
)
|
||||
:lexicon
|
||||
'(
|
||||
((Acknowledge $a) -> (yes true) (no false) (maybe unknown) (huh unparsed))
|
||||
((Adjunct $loc) -> here there (nearby near) near left right up down)
|
||||
((Article) -> a an the)
|
||||
((Aux $tense) -> (will future) (did past) (do $finite))
|
||||
((Be $tense) -> (am present) (are present) (is present) (be $finite)
|
||||
(was past) (were past))
|
||||
((Conjunction) -> and --)
|
||||
((Noun $n) -> gold Wumpus pit breeze stench glitter nothing)
|
||||
((Number $n) -> 0 1 2 3 4 5 6 7 8 9)
|
||||
((Prep $prep) -> in at to near)
|
||||
((Pronoun $n) -> (you self) (me master) (I master))
|
||||
|
||||
((Verb/in $rel $tense) -> (go move $finite) (went move past)
|
||||
(move move $finite) (move move past) (shoot shoot $finite))
|
||||
((Verb/tr $rel $tense) -> (move carry $finite) (moved carry past)
|
||||
(carry carry $finite) (carry carried past)
|
||||
(grab grab $finite) (grab grabbed past) (get grab $finite)
|
||||
(got grab past) (release release $finite) (release release past)
|
||||
(drop release $finite) (dropped release past) (shoot shoot-at $finite)
|
||||
(shot shoot-at past) (kill shoot-at $finite) (killed shoot-at past)
|
||||
(smell perceive $finite) (feel perceive $finite) (felt perceive past))
|
||||
((Verb/di $rel $tense) -> (bring bring $finite) (brought bring past)
|
||||
(get bring $finite) (got bring past))
|
||||
))
|
||||
|
||||
(defparameter *sentences*
|
||||
'((I will shoot the wumpus at 4 4)
|
||||
(yes)
|
||||
(You went right -- I will go left)
|
||||
(carry the gold)
|
||||
(yes and no)
|
||||
(did you bring me the gold)
|
||||
(a breeze is here -- I am near 5 3)
|
||||
(a stench is in 3 5)
|
||||
(a pit is nearby)
|
||||
(is the wumpus near)
|
||||
(Did you go to 3 8)
|
||||
(Yes -- Nothing is there)
|
||||
(Shoot -- Shoot left)
|
||||
(Kill the wumpus -- shoot up)))
|
||||
|
||||
(defun ss (&optional (sentences *sentences*))
|
||||
"Run some test sentences, and count how many were not parsed."
|
||||
(count-if-not
|
||||
#'(lambda (s)
|
||||
(format t "~2&>>> ~(~{~a ~}~)~%" s)
|
||||
(write (second (parse s)) :pretty t))
|
||||
*sentences*))
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 124 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,112 @@
|
||||
.TH XARGS 1L \" -*- nroff -*-
|
||||
.SH NAME
|
||||
xargs \- build and execute command lines from standard input
|
||||
.SH SYNOPSIS
|
||||
.B xargs
|
||||
[\-0prtx] [\-e[eof-str]] [\-i[replace-str]] [\-l[max-lines]]
|
||||
[\-n max-args] [\-s max-chars] [\-P max-procs] [\-\-null] [\-\-eof[=eof-str]]
|
||||
[\-\-replace[=replace-str]] [\-\-max-lines[=max-lines]] [\-\-interactive]
|
||||
[\-\-max-chars=max-chars] [\-\-verbose] [\-\-exit] [\-\-max-procs=max-procs]
|
||||
[\-\-max-args=max-args] [\-\-no-run-if-empty] [\-\-version] [\-\-help]
|
||||
[command [initial-arguments]]
|
||||
.SH DESCRIPTION
|
||||
This manual page
|
||||
documents the GNU version of
|
||||
.BR xargs .
|
||||
.B xargs
|
||||
reads arguments from the standard input, delimited by blanks (which can be
|
||||
protected with double or single quotes or a backslash) or newlines,
|
||||
and executes the
|
||||
.I command
|
||||
(default is /bin/echo) one or more times with any
|
||||
.I initial-arguments
|
||||
followed by arguments read from standard input. Blank lines on the
|
||||
standard input are ignored.
|
||||
.P
|
||||
.B xargs
|
||||
exits with the following status:
|
||||
.nf
|
||||
0 if it succeeds
|
||||
123 if any invocation of the command exited with status 1-125
|
||||
124 if the command exited with status 255
|
||||
125 if the command is killed by a signal
|
||||
126 if the command cannot be run
|
||||
127 if the command is not found
|
||||
1 if some other error occurred.
|
||||
.fi
|
||||
.SS OPTIONS
|
||||
.TP
|
||||
.I "\-\-null, \-0"
|
||||
Input filenames are terminated by a null character instead of by
|
||||
whitespace, and the quotes and backslash are not special (every
|
||||
character is taken literally). Disables the end of file string, which
|
||||
is treated like any other argument. Useful when arguments might
|
||||
contain white space, quote marks, or backslashes. The GNU find
|
||||
\-print0 option produces input suitable for this mode.
|
||||
.TP
|
||||
.I "\-\-eof[=eof-str], \-e[eof-str]"
|
||||
Set the end of file string to \fIeof-str\fR. If the end of file
|
||||
string occurs as a line of input, the rest of the input is ignored.
|
||||
If \fIeof-str\fR is omitted, there is no end of file string. If this
|
||||
option is not given, the end of file string defaults to "_".
|
||||
.TP
|
||||
.I "\-\-help"
|
||||
Print a summary of the options to
|
||||
.B xargs
|
||||
and exit.
|
||||
.TP
|
||||
.I "\-\-replace[=replace-str], \-i[replace-str]"
|
||||
Replace occurences of \fIreplace-str\fR in the initial arguments with
|
||||
names read from standard input.
|
||||
Also, unquoted blanks do not terminate arguments.
|
||||
If \fIreplace-str\fR is omitted, it
|
||||
defaults to "{}" (like for `find \-exec'). Implies \fI\-x\fP and
|
||||
\fI\-l 1\fP.
|
||||
.TP
|
||||
.I "\-\-max-lines[=max-lines], -l[max-lines]"
|
||||
Use at most \fImax-lines\fR nonblank input lines per command line;
|
||||
\fImax-lines\fR defaults to 1 if omitted. Trailing blanks cause an
|
||||
input line to be logically continued on the next input line. Implies
|
||||
\fI\-x\fR.
|
||||
.TP
|
||||
.I "\-\-max-args=max-args, \-n max-args"
|
||||
Use at most \fImax-args\fR arguments per command line. Fewer than
|
||||
\fImax-args\fR arguments will be used if the size (see the \-s option)
|
||||
is exceeded, unless the \-x option is given, in which case \fBxargs\fR
|
||||
will exit.
|
||||
.TP
|
||||
.I "\-\-interactive, \-p"
|
||||
Prompt the user about whether to run each command line and read a line
|
||||
from the terminal. Only run the command line if the response starts
|
||||
with `y' or `Y'. Implies \fI\-t\fR.
|
||||
.TP
|
||||
.I "\-\-no-run-if-empty, \-r"
|
||||
If the standard input does not contain any nonblanks, do not run the
|
||||
command. Normally, the command is run once even if there is no input.
|
||||
.TP
|
||||
.I "\-\-max-chars=max-chars, \-s max-chars"
|
||||
Use at most \fImax-chars\fR characters per command line, including the
|
||||
command and initial arguments and the terminating nulls at the ends of
|
||||
the argument strings. The default is as large as possible, up to 20k
|
||||
characters.
|
||||
.TP
|
||||
.I "\-\-verbose, \-t"
|
||||
Print the command line on the standard error output before executing
|
||||
it.
|
||||
.TP
|
||||
.I "\-\-version"
|
||||
Print the version number of
|
||||
.B xargs
|
||||
and exit.
|
||||
.TP
|
||||
.I "\-\-exit, \-x"
|
||||
Exit if the size (see the \fI\-s\fR option) is exceeded.
|
||||
.TP
|
||||
.I "\-\-max-procs=max-procs, \-P max-procs"
|
||||
Run up to \fImax-procs\fR processes at a time; the default is 1. If
|
||||
\fImax-procs\fR is 0, \fBxargs\fR will run as many processes as
|
||||
possible at a time. Use the \fI\-n\fR option with \fI\-P\fR;
|
||||
otherwise chances are that only one exec will be done.
|
||||
.SH "SEE ALSO"
|
||||
\fBfind\fP(1L), \fBlocate\fP(1L), \fBlocatedb\fP(5L), \fBupdatedb\fP(1)
|
||||
\fBFinding Files\fP (on-line in Info, or printed)
|
||||
@@ -0,0 +1,37 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2019 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
// We also need to import here all header files that
|
||||
// define globals so that consumers that use them despite
|
||||
// requesting them not to be declared with OPENVPN_EXTERN
|
||||
|
||||
#include <asio.hpp>
|
||||
#include <openvpn/log/logbasesimple.hpp>
|
||||
#include <openvpn/ssl/sslchoose.hpp>
|
||||
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest (&argc, argv);
|
||||
return RUN_ALL_TESTS ();
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2019 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <openvpn/common/exception.hpp>
|
||||
#include <openvpn/common/base64.hpp>
|
||||
|
||||
using namespace openvpn;
|
||||
|
||||
|
||||
#ifdef USE_OPENSSL
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
std::string ssllib_b64enc(const char* text, size_t textlen)
|
||||
{
|
||||
BIO *bio, *b64;
|
||||
|
||||
b64 = BIO_new(BIO_f_base64());
|
||||
bio = BIO_new(BIO_s_mem());
|
||||
bio = BIO_push(b64, bio);
|
||||
|
||||
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Ignore newlines - write everything in one line
|
||||
BIO_write(bio, text, (int)textlen);
|
||||
BIO_flush(bio);
|
||||
const char* encdata;
|
||||
long len = BIO_get_mem_data(bio, &encdata);
|
||||
|
||||
/* If there is nothing to encode OpenSSL gives back a nullptr */
|
||||
if (len == 0)
|
||||
encdata = "";
|
||||
|
||||
std::string ret(encdata, (size_t)len);
|
||||
BIO_free_all(bio);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
#include <mbedtls/base64.h>
|
||||
|
||||
std::string ssllib_b64enc(const char* text, size_t textlen)
|
||||
{
|
||||
size_t olen, outlen;
|
||||
|
||||
//make a pessimistic assumption about length always calculate 3 padding bytes
|
||||
outlen = 3 + 4*(textlen+3)/3;
|
||||
|
||||
char *dst = new char[outlen];
|
||||
|
||||
EXPECT_EQ(mbedtls_base64_encode(reinterpret_cast<unsigned char*>(dst), outlen,
|
||||
&olen, reinterpret_cast<const unsigned char*>(text), textlen), 0);
|
||||
std::string ret(dst, olen);
|
||||
delete[] dst;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void b64_test(const Base64& b64, const std::string& text)
|
||||
{
|
||||
const std::string enc = b64.encode(text);
|
||||
std::string dec = b64.decode(enc);
|
||||
std::string libenc = ssllib_b64enc(text.c_str(), text.size());
|
||||
|
||||
EXPECT_EQ(text, dec) << "Encode/Decode results differ";
|
||||
EXPECT_EQ(enc, libenc) << "Encode differs from Crypto lib result";
|
||||
}
|
||||
|
||||
void b64_test_binary(const Base64& b64, const char* data, unsigned int len)
|
||||
{
|
||||
auto enc = b64.encode(data, len);
|
||||
|
||||
char* decdata = new char[len];
|
||||
size_t decode_len = b64.decode(decdata, len, enc);
|
||||
std::string libenc = ssllib_b64enc(data, len);
|
||||
|
||||
EXPECT_EQ(enc, libenc) << "Encode differs from Crypto lib result";
|
||||
|
||||
ASSERT_EQ(decode_len, len) << "Encode/decode length differs";
|
||||
ASSERT_EQ(std::vector<uint8_t>(decdata, decdata + decode_len),
|
||||
std::vector<uint8_t>(data, data + len)) << "Encode/Decode results differ";
|
||||
|
||||
delete[] decdata;
|
||||
}
|
||||
|
||||
TEST(Base64, tooshortdest)
|
||||
{
|
||||
const Base64 b64;
|
||||
auto enc = b64.encode(std::string("abc"));
|
||||
|
||||
char buf[2];
|
||||
EXPECT_THROW(b64.decode(buf, 2, enc), Base64::base64_decode_out_of_bound_error);
|
||||
}
|
||||
|
||||
void b64_test_bad(const Base64& b64, const std::string& text)
|
||||
{
|
||||
std::string dec;
|
||||
EXPECT_THROW(b64.decode(dec, text), Base64::base64_decode_error);
|
||||
}
|
||||
|
||||
TEST(Base64, badencode)
|
||||
{
|
||||
const Base64 b64;
|
||||
|
||||
b64_test_bad(b64, "plausible deniability");
|
||||
b64_test_bad(b64, "plausible != deniability");
|
||||
b64_test_bad(b64, "x");
|
||||
b64_test_bad(b64, "====");
|
||||
b64_test_bad(b64, "xxxx=");
|
||||
b64_test_bad(b64, "01*=");
|
||||
}
|
||||
|
||||
TEST(Base64, encode)
|
||||
{
|
||||
const Base64 b64;
|
||||
|
||||
b64_test(b64, "Hello world!");
|
||||
b64_test(b64, "привет!");
|
||||
b64_test(b64, "ûmbrellaûmbrella");
|
||||
b64_test(b64, "一旦在一个蓝色的月亮");
|
||||
b64_test(b64, "x");
|
||||
b64_test(b64, "one two three");
|
||||
b64_test(b64, "aa");
|
||||
b64_test(b64, "get your kicks on ... route 66");
|
||||
b64_test(b64, "fight the future");
|
||||
b64_test(b64, "");
|
||||
b64_test(b64, "I want to believe...");
|
||||
b64_test(b64, "it was a weather balloon");
|
||||
b64_test(b64, "hyperspatial bypass");
|
||||
b64_test(b64, "ode to a vogon");
|
||||
b64_test(b64, "Acme Travel");
|
||||
b64_test(b64, "there's no sunshine when she's gone");
|
||||
b64_test(b64, "??????????????????????");
|
||||
b64_test(b64, "???????????????????????");
|
||||
b64_test(b64, "????????????????????????");
|
||||
b64_test(b64, "???x>>>>>>>>>?????????????");
|
||||
b64_test(b64, "???x>>>>>>>>>??????????????");
|
||||
b64_test(b64, "???x>>>>>>>>>?????????????x>>");
|
||||
}
|
||||
|
||||
TEST(Base64, binary_data)
|
||||
{
|
||||
|
||||
const Base64 b64;
|
||||
std::srand(0);
|
||||
for(unsigned int i=0;i<20;i++)
|
||||
{
|
||||
char* data = new char[i];
|
||||
for (int j=0;j<i;j++)
|
||||
{
|
||||
data[j]=(char)(std::rand() & 0xff);
|
||||
}
|
||||
b64_test_binary(b64, data, i);
|
||||
delete[] data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2019 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
|
||||
#pragma once
|
||||
|
||||
/* Globals get defined multiple times, normally we set this to extern
|
||||
* in the part of the program that pulls in a subset of the other
|
||||
* In the unit tests that does not work. So all unit tests are told not
|
||||
* to include them and all includes are included in core_tests.cpp to pull
|
||||
* them in
|
||||
*/
|
||||
#define OPENVPN_EXTERN extern
|
||||
|
||||
/* Without the asio.hpp include we get winsocket.h related errors
|
||||
* See also https://stackoverflow.com/questions/9750344/boostasio-winsock-and-winsock-2-compatibility-issue
|
||||
*/
|
||||
#include <asio.hpp>
|
||||
#include <openvpn/log/logbasesimple.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -0,0 +1,262 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2017 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm> // for std::min
|
||||
|
||||
#ifndef BLOCK_SIZE
|
||||
#define BLOCK_SIZE 1500
|
||||
#endif
|
||||
|
||||
#ifndef N_COMPRESS
|
||||
#define N_COMPRESS 1
|
||||
#endif
|
||||
|
||||
#ifndef N_EXPAND
|
||||
#define N_EXPAND 1
|
||||
#endif
|
||||
|
||||
#ifndef SUPPORT_SWAP
|
||||
#define SUPPORT_SWAP false
|
||||
#endif
|
||||
|
||||
// other defines:
|
||||
// must define TEST_x to define compressor/decompressor pair
|
||||
// OPENVPN_DEBUG_COMPRESS = 0|1|2
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include <openvpn/common/size.hpp>
|
||||
#include <openvpn/common/exception.hpp>
|
||||
#include <openvpn/common/file.hpp>
|
||||
#include <openvpn/buffer/buffer.hpp>
|
||||
#include <openvpn/compress/compress.hpp>
|
||||
#include <openvpn/compress/lzoasym.hpp>
|
||||
#include <openvpn/frame/frame.hpp>
|
||||
|
||||
using namespace openvpn;
|
||||
|
||||
Frame::Ptr frame_init(const size_t payload)
|
||||
{
|
||||
const size_t headroom = 512;
|
||||
const size_t tailroom = 512;
|
||||
const size_t align_block = 16;
|
||||
const unsigned int buffer_flags = 0;
|
||||
|
||||
Frame::Ptr frame(new Frame(Frame::Context(headroom, payload, tailroom, 0, align_block, buffer_flags)));
|
||||
frame->standardize_capacity(~0);
|
||||
return frame;
|
||||
}
|
||||
|
||||
class MySessionStats : public SessionStats
|
||||
{
|
||||
public:
|
||||
typedef RCPtr<MySessionStats> Ptr;
|
||||
|
||||
MySessionStats()
|
||||
{
|
||||
std::memset(errors, 0, sizeof(errors));
|
||||
}
|
||||
|
||||
virtual void error(const size_t err_type, const std::string* text=NULL)
|
||||
{
|
||||
if (err_type < Error::N_ERRORS)
|
||||
++errors[err_type];
|
||||
}
|
||||
|
||||
count_t get_error_count(const Error::Type type) const
|
||||
{
|
||||
if (type < Error::N_ERRORS)
|
||||
return errors[type];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
count_t errors[Error::N_ERRORS];
|
||||
};
|
||||
|
||||
inline void verify_eq(const Buffer& b1, const Buffer& b2)
|
||||
{
|
||||
ASSERT_EQ(b1, b2) << "decompressed data doesn't match original data";
|
||||
}
|
||||
|
||||
void test(const std::string& filename,
|
||||
Compress& compressor,
|
||||
Compress& decompressor,
|
||||
const Frame& frame,
|
||||
const size_t block_size,
|
||||
const size_t n_compress,
|
||||
const size_t n_expand_per_compress,
|
||||
size_t& bytes,
|
||||
size_t& compress_bytes)
|
||||
{
|
||||
BufferPtr source_data = read_binary(filename);
|
||||
for (size_t offset = 0; offset < source_data->size(); offset += block_size)
|
||||
{
|
||||
const size_t length = std::min(block_size, source_data->size() - offset);
|
||||
BufferAllocated data_seg;
|
||||
frame.prepare(Frame::DECRYPT_WORK, data_seg);
|
||||
data_seg.write(source_data->data_raw() + offset, length);
|
||||
for (size_t compress_iter = 0; compress_iter < n_compress; ++compress_iter)
|
||||
{
|
||||
BufferAllocated data1(data_seg);
|
||||
bytes += data1.size();
|
||||
compressor.compress(data1, true);
|
||||
compress_bytes += data1.size();
|
||||
if (n_expand_per_compress == 1)
|
||||
{
|
||||
decompressor.decompress(data1);
|
||||
verify_eq(data_seg, data1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t decompress_iter = 0; decompress_iter < n_expand_per_compress; ++decompress_iter)
|
||||
{
|
||||
BufferAllocated data2(data1);
|
||||
decompressor.decompress(data2);
|
||||
verify_eq(data_seg, data2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_with_corpus(Compress& compressor,
|
||||
Compress& decompressor,
|
||||
const Frame& frame,
|
||||
const size_t block_size,
|
||||
const size_t n_compress,
|
||||
const size_t n_expand_per_compress,
|
||||
size_t& bytes,
|
||||
size_t& compress_bytes)
|
||||
{
|
||||
static const std::vector<std::string> filenames = {
|
||||
"comp-testdata/alice29.txt",
|
||||
"comp-testdata/asyoulik.txt",
|
||||
"comp-testdata/cp.html",
|
||||
"comp-testdata/fields.c",
|
||||
"comp-testdata/geo.protodata",
|
||||
"comp-testdata/grammar.lsp",
|
||||
"comp-testdata/house.jpg",
|
||||
"comp-testdata/html",
|
||||
"comp-testdata/html_x_4",
|
||||
"comp-testdata/kennedy.xls",
|
||||
"comp-testdata/kppkn.gtb",
|
||||
"comp-testdata/lcet10.txt",
|
||||
"comp-testdata/mapreduce-osdi-1.pdf",
|
||||
"comp-testdata/plrabn12.txt",
|
||||
"comp-testdata/ptt5",
|
||||
"comp-testdata/sum",
|
||||
"comp-testdata/urls.10K",
|
||||
"comp-testdata/xargs.1",
|
||||
};
|
||||
for (auto fn: filenames) {
|
||||
test(UNITTEST_SOURCE_DIR + fn, compressor, decompressor, frame, block_size, n_compress, n_expand_per_compress, bytes,
|
||||
compress_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
enum class comppair {
|
||||
lzo,
|
||||
lzoasym,
|
||||
snappy,
|
||||
lz4
|
||||
};
|
||||
|
||||
void runTest(comppair alg, bool verbose=false)
|
||||
{
|
||||
CompressContext::init_static();
|
||||
MySessionStats::Ptr stats(new MySessionStats);
|
||||
Frame::Ptr frame = frame_init(BLOCK_SIZE);
|
||||
|
||||
|
||||
Compress::Ptr compress;
|
||||
Compress::Ptr decompress;
|
||||
|
||||
switch (alg) {
|
||||
#if defined(HAVE_LZO)
|
||||
case comppair::lzoasym:
|
||||
compress.reset(new CompressLZO(frame, stats, SUPPORT_SWAP, false));
|
||||
decompress.reset(new CompressLZOAsym(frame, stats, SUPPORT_SWAP, false));
|
||||
break;
|
||||
|
||||
case comppair::lzo:
|
||||
compress.reset(new CompressLZO(frame, stats, SUPPORT_SWAP, false));
|
||||
decompress = compress;
|
||||
break;
|
||||
|
||||
#endif
|
||||
#if defined(HAVE_LZ4)
|
||||
case comppair::lz4:
|
||||
compress.reset(new CompressLZ4(frame, stats, false));
|
||||
decompress = compress;
|
||||
break;
|
||||
#endif
|
||||
#if defined(HAVE_SNAPPY)
|
||||
case comppair::snappy:
|
||||
compress.reset(new CompressSnappy(frame, stats, false));
|
||||
decompress = compress;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ASSERT_TRUE(false) << "compressor/decompressor pair not supported";
|
||||
}
|
||||
size_t bytes = 0;
|
||||
size_t compress_bytes = 0;
|
||||
test_with_corpus(*compress, *decompress, *frame, BLOCK_SIZE, N_COMPRESS, N_EXPAND, bytes, compress_bytes);
|
||||
|
||||
if (verbose)
|
||||
std::cout << "comp=" << compress->name() << '[' << N_COMPRESS << ']'
|
||||
<< " decomp=" << decompress->name() << '[' << N_EXPAND << ']'
|
||||
<< " blk=" << BLOCK_SIZE
|
||||
<< " bytes=" << bytes
|
||||
<< " comp-bytes=" << compress_bytes
|
||||
<< " comp-ratio=" << (float) compress_bytes / bytes
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
namespace unittests
|
||||
{
|
||||
#if defined(HAVE_SNAPPY)
|
||||
TEST(Compression, snappy)
|
||||
{
|
||||
runTest(comppair::snappy);
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_LZO)
|
||||
TEST(Compression, lzo)
|
||||
{
|
||||
runTest(comppair::lzo);
|
||||
}
|
||||
|
||||
TEST(Compression, lzoasym)
|
||||
{
|
||||
runTest(comppair::lzoasym);
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_LZ4)
|
||||
TEST(Compression, lz4)
|
||||
{
|
||||
runTest(comppair::lz4);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2019 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
// We have two set of measurements for these tests
|
||||
//
|
||||
// 1. A coarse measurement based on time()
|
||||
// These are tracked in 'chk_start' and 'chk_end'
|
||||
//
|
||||
// 2. A fine grained measurement from cpu_time()
|
||||
// These are tracked in 'start' and 'end'
|
||||
//
|
||||
// We calculate the difference before and after a
|
||||
// a workload has run, to measure how long it ran.
|
||||
// This is done for both measurement approaches.
|
||||
// The runtime is saved in runtime and chk_runtime
|
||||
//
|
||||
// To pass this test, absolute difference between
|
||||
// runtime and chk_runtime must be less than 1 second.
|
||||
//
|
||||
|
||||
//#define DEBUG // Define this macro to get more details
|
||||
|
||||
#include "test_common.h"
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
#include <openvpn/linux/cputime.hpp>
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_DUMP(msg, st, en, rt, chst, chen, chrt, md) \
|
||||
std::cout << msg << std::endl \
|
||||
<< "start = " << std::to_string(st) << std::endl \
|
||||
<< "end = " << std::to_string(en) << std::endl \
|
||||
<< "runtime = " << std::to_string(rt) << std::endl \
|
||||
<< "chk_start = " << std::to_string(chst) << std::endl \
|
||||
<< "chk_end = " << std::to_string(chen) << std::endl \
|
||||
<< "chk_runtime = " << std::to_string(chrt) << std::endl \
|
||||
<< "measurement difference = " \
|
||||
<< std::to_string(md) << std::endl \
|
||||
<< "--------------------------------------" << std::endl
|
||||
|
||||
#else
|
||||
#define DEBUG_DUMP(msg, st, en, rt, chst, chen, chrt, md) {}
|
||||
#endif
|
||||
|
||||
#define MEASURE(v, chkv, thread) \
|
||||
double v = openvpn::cpu_time(thread); \
|
||||
ASSERT_GE(v, 0); \
|
||||
double chkv = time(NULL)
|
||||
|
||||
#define CALCULATE(msg, st, en, rt, chst, chen, chrt, md) \
|
||||
double rt = en - st; \
|
||||
double chrt = chen - chst; \
|
||||
double md = std::max(rt, chrt) - std::min(rt, chrt); \
|
||||
DEBUG_DUMP(msg, st, en, rt, chst, chen, chrt, md)
|
||||
|
||||
|
||||
typedef std::shared_ptr<std::thread> ThreadPtr;
|
||||
|
||||
|
||||
// For simplicty, keep the total thread runtime
|
||||
// in a global variable, protected by a mutex
|
||||
// on updates
|
||||
std::mutex update_guard;
|
||||
double thread_runtime = 0;
|
||||
|
||||
void update_thread_runtime(double val)
|
||||
{
|
||||
std::lock_guard<std::mutex> ug(update_guard);
|
||||
thread_runtime += val;
|
||||
}
|
||||
|
||||
|
||||
namespace unittests
|
||||
{
|
||||
static void workload(const uint16_t multiplier)
|
||||
{
|
||||
// A very simple busy loop workload
|
||||
//
|
||||
// We can't use sleep() or any similar timing
|
||||
// as this does not increase the tracked runtime
|
||||
// in the kernel; the process does not really run.
|
||||
//
|
||||
std::stringstream buf;
|
||||
for (unsigned int i = UINT16_MAX * multiplier; i > 0; i--)
|
||||
{
|
||||
buf << ".";
|
||||
|
||||
// We do this clearing to not spend too much
|
||||
// memory when running multiple threads
|
||||
buf.str(std::string());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(LinuxCPUTime, cpu_time_pid)
|
||||
{
|
||||
// Measure the runtime of the workload
|
||||
MEASURE(start, chk_start, false);
|
||||
workload(1500);
|
||||
MEASURE(end, chk_end, false);
|
||||
|
||||
// Calculate runtimes and differences
|
||||
CALCULATE("single PID",
|
||||
start, end, runtime,
|
||||
chk_start, chk_end, chk_runtime,
|
||||
measurement_diff);
|
||||
|
||||
ASSERT_LT(measurement_diff, 1);
|
||||
}
|
||||
|
||||
|
||||
void worker_thread(const uint8_t id)
|
||||
{
|
||||
MEASURE(thr_start, chk_thr_start, true);
|
||||
workload(1500);
|
||||
MEASURE(thr_end, chk_thr_end, true);
|
||||
|
||||
CALCULATE("Worker thread " << std::to_string(id),
|
||||
thr_start, thr_end, thr_runtime,
|
||||
chk_thr_start, chk_thr_end, chk_thr_runtime,
|
||||
thr_measurement_diff);
|
||||
update_thread_runtime(thr_runtime);
|
||||
|
||||
// Since the chk_thr_runtime (chk_thr_end - chk_thr_start)
|
||||
// is based on epoc seconds of the system, this doesn't
|
||||
// give a too good number when running multiple threads.
|
||||
//
|
||||
// If more threads are running on the same CPU core,
|
||||
// one of the threads might be preempted. The clock time
|
||||
// (chk_thr_runtime) will continue to tick, but the real
|
||||
// runtime (thr_runtime) will not. Which will increase
|
||||
// the difference between the measured runtimes.
|
||||
//
|
||||
// The value of 5 is just an educated guess of what
|
||||
// we might find acceptable. This might be too high
|
||||
// on an idle system, but too low on a loaded system.
|
||||
//
|
||||
ASSERT_LT(thr_measurement_diff, 5);
|
||||
}
|
||||
|
||||
|
||||
void run_threads(const uint8_t num_threads)
|
||||
{
|
||||
std::vector<ThreadPtr> threads;
|
||||
for (uint8_t i = 0; i < num_threads; i++)
|
||||
{
|
||||
ThreadPtr tp;
|
||||
tp.reset(new std::thread([id=i](){ worker_thread(id); }));
|
||||
threads.push_back(tp);
|
||||
}
|
||||
|
||||
for (const auto& t : threads)
|
||||
{
|
||||
t->join();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(LinuxCPUTime, cpu_time_thread_1)
|
||||
{
|
||||
// Meassure running a single worker thread
|
||||
MEASURE(parent_start, chk_parent_start, false);
|
||||
run_threads(1);
|
||||
MEASURE(parent_end, chk_parent_end, false);
|
||||
|
||||
CALCULATE("Parent thread - 1 child thread",
|
||||
parent_start, parent_end, runtime,
|
||||
chk_parent_start, chk_parent_end, chk_runtime,
|
||||
parent_diff);
|
||||
|
||||
ASSERT_LT(parent_diff, 1);
|
||||
}
|
||||
|
||||
|
||||
TEST(LinuxCPUTime, cpu_time_thread_numcores)
|
||||
{
|
||||
// Use number of available cores
|
||||
int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
||||
// Meassure running a single worker thread
|
||||
MEASURE(parent_start, chk_parent_start, false);
|
||||
run_threads(num_cores);
|
||||
MEASURE(parent_end, chk_parent_end, false);
|
||||
|
||||
CALCULATE("Parent thread - " << std::to_string(num_cores) << " child thread",
|
||||
parent_start, parent_end, runtime,
|
||||
chk_parent_start, chk_parent_end, chk_runtime,
|
||||
parent_diff);
|
||||
#ifdef DEBUG
|
||||
std::cout << "Total thread runtime: " << std::to_string(thread_runtime) << std::endl;
|
||||
#endif
|
||||
|
||||
// The main process (this PID) will have a total runtime
|
||||
// which accounts for all runtime of the running threads.
|
||||
// We still give a bit extra slack, to reduce the risk of
|
||||
// false positives, due to the possibility of premption
|
||||
// (see comment in worker_thread() for details). But
|
||||
// the difference should not neccesarily deviate as much
|
||||
// here.
|
||||
ASSERT_LT(parent_diff, 3 + thread_runtime);
|
||||
}
|
||||
} // namespace
|
||||
@@ -0,0 +1,53 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2017 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
|
||||
// The ovpncli.cpp file is not all OPENVPN_EXTERN safe and totally breaks
|
||||
// if included in two files. We probably need to fix this or rename this
|
||||
// file test_ovpncli and do ALL test that require ovpncli in this file
|
||||
// (or have multiple test suites)
|
||||
|
||||
// This file needs to included with OPENVPN_EXTERN still defined otherwise
|
||||
// the include from ovpncli.cpp breaks with duplicate symbols
|
||||
#include <openvpn/common/base64.hpp>
|
||||
|
||||
#undef OPENVPN_EXTERN
|
||||
#define OPENVPN_EXTERN
|
||||
|
||||
#include <client/ovpncli.cpp>
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace unittests
|
||||
{
|
||||
TEST(LogInfoTest, TestLogInfo)
|
||||
{
|
||||
std::string msg("logMessage");
|
||||
openvpn::ClientAPI::LogInfo logInfo(msg);
|
||||
auto text = logInfo.text;
|
||||
|
||||
ASSERT_EQ(text, msg);
|
||||
}
|
||||
} // namespace
|
||||
@@ -0,0 +1,296 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2019 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
|
||||
/* Without doing this log dance core will not compile ... */
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include <openvpn/client/cliemuexr.hpp>
|
||||
|
||||
|
||||
namespace unittests {
|
||||
#define DEBUG_PRINT_ROUTES for(auto & rt: tb->routes) std::cout << rt << std::endl;
|
||||
|
||||
/* Helper function for quick result comparision */
|
||||
std::string join_string_vector_sorted(std::vector<std::string> vec, const char* const delim = ", ")
|
||||
{
|
||||
std::sort(vec.begin(), vec.end());
|
||||
std::ostringstream res;
|
||||
std::copy(vec.begin(), vec.end(), std::ostream_iterator<std::string>(res, delim));
|
||||
return res.str();
|
||||
}
|
||||
|
||||
/* Simple class that just records */
|
||||
class TunBuilderMock : public openvpn::TunBuilderBase {
|
||||
public:
|
||||
bool is_ipv6;
|
||||
TunBuilderMock(bool ipv6)
|
||||
:is_ipv6(ipv6)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool tun_builder_add_route(const std::string& address,
|
||||
int prefix_length,
|
||||
int metric,
|
||||
bool ipv6) override
|
||||
{
|
||||
auto rt = address+"/"+std::to_string(prefix_length);
|
||||
routes.push_back(rt);
|
||||
routesAddr.push_back(openvpn::IP::Route(rt));
|
||||
return is_ipv6==ipv6;
|
||||
}
|
||||
|
||||
bool tun_builder_set_remote_address(const std::string& address, bool ipv6) override
|
||||
{
|
||||
addresses.push_back(address);
|
||||
return is_ipv6==ipv6;
|
||||
}
|
||||
|
||||
std::vector<std::string> addresses;
|
||||
std::vector<std::string> routes;
|
||||
std::vector<openvpn::IP::Route> routesAddr;
|
||||
|
||||
bool containsIP(std::string ipaddr)
|
||||
{
|
||||
return containsIP(openvpn::IP::Addr(ipaddr));
|
||||
}
|
||||
|
||||
bool containsIP(openvpn::IP::Addr ipaddr)
|
||||
{
|
||||
for (auto& rt: routesAddr) {
|
||||
if (rt.contains(ipaddr))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class RouteEmulationTest : public testing::Test {
|
||||
protected:
|
||||
openvpn::IPVerFlags* ipflags;
|
||||
openvpn::EmulateExcludeRoute::Ptr emu;
|
||||
TunBuilderMock* tb;
|
||||
openvpn::OptionList emptyOptionList;
|
||||
|
||||
RouteEmulationTest()
|
||||
:tb(nullptr), ipflags(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void teardown()
|
||||
{
|
||||
delete tb;
|
||||
delete ipflags;
|
||||
}
|
||||
|
||||
void setup(bool ipv6, bool excludeServer, bool keepEmu = false)
|
||||
{
|
||||
teardown();
|
||||
|
||||
tb = new TunBuilderMock(ipv6);
|
||||
|
||||
ipflags = new openvpn::IPVerFlags(emptyOptionList,
|
||||
ipv6 ? openvpn::IP::Addr::V6_MASK : openvpn::IP::Addr::V4_MASK);
|
||||
|
||||
if (!keepEmu)
|
||||
{
|
||||
openvpn::EmulateExcludeRouteFactory::Ptr factory(
|
||||
new openvpn::EmulateExcludeRouteFactoryImpl(excludeServer));
|
||||
|
||||
emu = factory->new_obj();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper functions to make writing test suite a bit easier
|
||||
void inclRoute(const std::string& incRoute)
|
||||
{
|
||||
addRoute(true, incRoute);
|
||||
}
|
||||
void exclRoute(const std::string& exclRoute)
|
||||
{
|
||||
addRoute(false, exclRoute);
|
||||
}
|
||||
|
||||
void addRoute(bool include, const std::string& route)
|
||||
{
|
||||
std::string ipstr = route.substr(0, route.find('/'));
|
||||
std::string mask = route.substr(route.find('/')+1);
|
||||
emu->add_route(include, openvpn::IP::Addr(ipstr), std::stoi(mask));
|
||||
}
|
||||
|
||||
void doEmulate(std::string serverip = "1.2.3.4")
|
||||
{
|
||||
emu->emulate(this->tb, *this->ipflags, openvpn::IP::Addr(serverip));
|
||||
}
|
||||
|
||||
~RouteEmulationTest()
|
||||
{
|
||||
teardown();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(RouteEmulationTest, ExcludeOneSubnet)
|
||||
{
|
||||
setup(false, false);
|
||||
|
||||
emu->add_default_routes(true, true);
|
||||
|
||||
emu->add_route(false, openvpn::IP::Addr("192.168.100.0"), 24);
|
||||
|
||||
doEmulate();
|
||||
|
||||
ASSERT_EQ (tb->routes.size(), 24);
|
||||
|
||||
}
|
||||
|
||||
TEST_F(RouteEmulationTest, ExcludeSubnetsNoDefault)
|
||||
{
|
||||
setup(false, false);
|
||||
// include this net
|
||||
emu->add_route(true, openvpn::IP::Addr("10.20.0.0"), 16);
|
||||
|
||||
// but not the first half
|
||||
emu->add_route(false, openvpn::IP::Addr("10.20.0.0"), 17);
|
||||
|
||||
doEmulate();
|
||||
|
||||
ASSERT_EQ(tb->routes.size(), 1);
|
||||
ASSERT_EQ(tb->routes.at(0), "10.20.128.0/17");
|
||||
|
||||
setup(true, false);
|
||||
|
||||
emu->add_route(true, openvpn::IP::Addr("2500:1000::"), 32);
|
||||
// but not the first half
|
||||
emu->add_route(false, openvpn::IP::Addr("2500:1000:8000::"), 33);
|
||||
|
||||
doEmulate();
|
||||
|
||||
ASSERT_EQ(tb->routes.size(), 1);
|
||||
ASSERT_EQ(tb->routes.at(0), "2500:1000::/33");
|
||||
|
||||
}
|
||||
|
||||
TEST_F(RouteEmulationTest, excludeServer)
|
||||
{
|
||||
setup(false, true);
|
||||
emu->add_default_routes(true, true);
|
||||
doEmulate("1.2.3.4");
|
||||
|
||||
ASSERT_EQ(tb->routes.size(), 32);
|
||||
ASSERT_FALSE(tb->containsIP("1.2.3.4"));
|
||||
ASSERT_TRUE(tb->containsIP("1.2.3.5"));
|
||||
ASSERT_TRUE(tb->containsIP("1.2.3.3"));
|
||||
ASSERT_TRUE(tb->containsIP("4.3.2.1"));
|
||||
|
||||
setup(true, true);
|
||||
emu->add_default_routes(true, true);
|
||||
doEmulate("::1.2.3.4");
|
||||
|
||||
ASSERT_EQ(tb->routes.size(), 128);
|
||||
ASSERT_FALSE(tb->containsIP("::1.2.3.4"));
|
||||
ASSERT_TRUE(tb->containsIP("::1.2.3.5"));
|
||||
ASSERT_TRUE(tb->containsIP("::1.2.3.3"));
|
||||
ASSERT_TRUE(tb->containsIP("::4.3.2.1"));
|
||||
}
|
||||
|
||||
TEST_F(RouteEmulationTest, nestedIPRoutes)
|
||||
{
|
||||
// This sets up a number of routes that are all included in each
|
||||
|
||||
setup(false, false);
|
||||
inclRoute("192.64.0.0/16");
|
||||
// second quarter.
|
||||
exclRoute("192.64.64.0/18");
|
||||
// last quarter
|
||||
inclRoute("192.64.112.0/20");
|
||||
// first quarter
|
||||
exclRoute("192.64.112.0/22");
|
||||
// first quarter again
|
||||
inclRoute("192.64.112.0/24");
|
||||
// second quarter
|
||||
exclRoute("192.64.112.64/26");
|
||||
|
||||
doEmulate();
|
||||
|
||||
// Excluded by 192.64.112.64/26
|
||||
ASSERT_FALSE(tb->containsIP("192.64.112.64"));
|
||||
ASSERT_FALSE(tb->containsIP("192.64.112.87"));
|
||||
|
||||
// Included by 192.64.112.0/24
|
||||
ASSERT_TRUE(tb->containsIP("192.64.112.5"));
|
||||
ASSERT_TRUE(tb->containsIP("192.64.112.129"));
|
||||
ASSERT_TRUE(tb->containsIP("192.64.112.255"));
|
||||
|
||||
// Excluded by 192.64.112.0/22
|
||||
ASSERT_FALSE(tb->containsIP("192.64.113.91"));
|
||||
ASSERT_FALSE(tb->containsIP("192.64.114.92"));
|
||||
ASSERT_FALSE(tb->containsIP("192.64.115.93"));
|
||||
|
||||
|
||||
// Included by 192.64.112.0/20
|
||||
ASSERT_TRUE(tb->containsIP("192.64.116.94"));
|
||||
ASSERT_TRUE(tb->containsIP("192.64.123.95"));
|
||||
|
||||
|
||||
// Excluded by 192.64.64.0/18"
|
||||
ASSERT_FALSE(tb->containsIP("192.64.64.96"));
|
||||
ASSERT_FALSE(tb->containsIP("192.64.97.98"));
|
||||
ASSERT_FALSE(tb->containsIP("192.64.111.99"));
|
||||
|
||||
// included in 192.64.0.0/16
|
||||
ASSERT_TRUE(tb->containsIP("192.64.0.0"));
|
||||
ASSERT_TRUE(tb->containsIP("192.64.1.2"));
|
||||
|
||||
// Not in the at all
|
||||
ASSERT_FALSE(tb->containsIP("1.2.3.4"));
|
||||
ASSERT_FALSE(tb->containsIP("192.63.255.255"));
|
||||
ASSERT_FALSE(tb->containsIP("192.65.0.0"));
|
||||
ASSERT_FALSE(tb->containsIP("128.0.0.0"));
|
||||
ASSERT_FALSE(tb->containsIP("192.0.0.0"));
|
||||
ASSERT_FALSE(tb->containsIP("255.255.255.255"));
|
||||
}
|
||||
|
||||
TEST_F(RouteEmulationTest, DefaultRoute)
|
||||
{
|
||||
setup(false, false);
|
||||
|
||||
emu->add_default_routes(true, true);
|
||||
|
||||
doEmulate();
|
||||
|
||||
ASSERT_EQ(tb->routes.size(), 1);
|
||||
ASSERT_EQ(tb->routes.at(0), "0.0.0.0/0");
|
||||
|
||||
// Now something more tricky add unnecessary extra route
|
||||
// to confuse our emulation layer
|
||||
setup(false, false, true);
|
||||
|
||||
inclRoute("192.168.0.0/24");
|
||||
|
||||
doEmulate();
|
||||
|
||||
ASSERT_EQ(tb->routes.size(), 2);
|
||||
ASSERT_EQ(tb->routes.at(0), "0.0.0.0/0");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2019 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
|
||||
#include <fstream>
|
||||
#include "test_common.h"
|
||||
|
||||
#include "openvpn/common/argv.hpp"
|
||||
#include "openvpn/common/process.hpp"
|
||||
#include "openvpn/common/redir.hpp"
|
||||
#include "openvpn/common/splitlines.hpp"
|
||||
|
||||
#include "openvpn/tun/linux/client/sitnl.hpp"
|
||||
|
||||
using namespace openvpn;
|
||||
using namespace TunNetlink;
|
||||
|
||||
namespace unittests
|
||||
{
|
||||
static std::string path_to_ip;
|
||||
|
||||
class SitnlTest : public testing::Test
|
||||
{
|
||||
private:
|
||||
void add_device(std::string name)
|
||||
{
|
||||
RedirectPipe::InOut pipe;
|
||||
Argv argv;
|
||||
argv.emplace_back(path_to_ip);
|
||||
argv.emplace_back("tuntap");
|
||||
argv.emplace_back("add");
|
||||
argv.emplace_back("mode");
|
||||
argv.emplace_back("tun");
|
||||
argv.emplace_back(std::move(name));
|
||||
system_cmd(argv[0], argv, nullptr, pipe, 0);
|
||||
}
|
||||
|
||||
void remove_device(std::string name)
|
||||
{
|
||||
RedirectPipe::InOut pipe;
|
||||
Argv argv;
|
||||
argv.emplace_back(path_to_ip);
|
||||
argv.emplace_back("tuntap");
|
||||
argv.emplace_back("delete");
|
||||
argv.emplace_back("mode");
|
||||
argv.emplace_back("tun");
|
||||
argv.emplace_back(std::move(name));
|
||||
system_cmd(argv[0], argv, nullptr, pipe, 0);
|
||||
}
|
||||
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
// different distros have ip tool in different places
|
||||
std::vector<std::string> paths{"/bin/ip", "/sbin/ip", "/usr/bin/ip", "/usr/sbin/ip"};
|
||||
for (const auto& path : paths)
|
||||
{
|
||||
std::ifstream f(path);
|
||||
if (f)
|
||||
{
|
||||
path_to_ip = path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ASSERT_FALSE(path_to_ip.empty()) << "unable to find ip tool";
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
if (geteuid() != 0)
|
||||
GTEST_SKIP() << "Need root to run this test";
|
||||
|
||||
add_device(dev);
|
||||
add_device(dev2);
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
remove_device(dev);
|
||||
remove_device(dev2);
|
||||
}
|
||||
|
||||
template <typename CALLBACK>
|
||||
void cmd(Argv argv, CALLBACK cb)
|
||||
{
|
||||
// runs command, reads output and calls a callback
|
||||
RedirectPipe::InOut pipe;
|
||||
ASSERT_EQ(system_cmd(argv[0], argv, nullptr, pipe, 0), 0) << "failed to run command " << argv[0];
|
||||
|
||||
SplitLines sl(pipe.out);
|
||||
bool called = false;
|
||||
while (sl()) {
|
||||
const std::string &line = sl.line_ref();
|
||||
|
||||
std::vector<std::string> v = Split::by_space<std::vector<std::string>, NullLex, SpaceMatch, Split::NullLimit>(line);
|
||||
|
||||
// blank line?
|
||||
if (v.empty())
|
||||
continue;
|
||||
|
||||
cb(v, pipe.out, called);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(called) << pipe.out;
|
||||
}
|
||||
|
||||
template <typename CALLBACK>
|
||||
void ip_a_show_dev(CALLBACK cb)
|
||||
{
|
||||
// get addrs with "ip a show dev"
|
||||
RedirectPipe::InOut pipe;
|
||||
Argv argv;
|
||||
argv.emplace_back(path_to_ip);
|
||||
argv.emplace_back("a");
|
||||
argv.emplace_back("show");
|
||||
argv.emplace_back("dev");
|
||||
argv.emplace_back(dev);
|
||||
cmd(argv, cb);
|
||||
}
|
||||
|
||||
template <typename CALLBACK>
|
||||
void ip_route_get(std::string dst, CALLBACK cb)
|
||||
{
|
||||
// get route with "ip route get"
|
||||
RedirectPipe::InOut pipe;
|
||||
Argv argv;
|
||||
argv.emplace_back(path_to_ip);
|
||||
argv.emplace_back("route");
|
||||
argv.emplace_back("get");
|
||||
argv.emplace_back(std::move(dst));
|
||||
cmd(argv, cb);
|
||||
}
|
||||
|
||||
std::string dev = "tun999";
|
||||
std::string dev2 = "tun9999";
|
||||
|
||||
std::string addr4 = "10.10.0.2";
|
||||
std::string route4 = "10.110.0.0/24";
|
||||
std::string gw4 = "10.10.0.1";
|
||||
|
||||
std::string addr6 = "fe80:20c3:aaaa:bbbb::cccc";
|
||||
std::string route6 = "fe80:20c3:cccc:dddd::0/64";
|
||||
std::string gw6 = "fe80:20c3:aaaa:bbbb:cccc:dddd:eeee:1";
|
||||
|
||||
int ipv4_prefix_len = 16;
|
||||
int ipv6_prefix_len = 64;
|
||||
int mtu = 1234;
|
||||
};
|
||||
|
||||
TEST_F(SitnlTest, TestAddrAdd4)
|
||||
{
|
||||
auto broadcast = IPv4::Addr::from_string(addr4) | ~IPv4::Addr::netmask_from_prefix_len(ipv4_prefix_len);
|
||||
ASSERT_EQ(SITNL::net_addr_add(dev, IPv4::Addr::from_string(addr4), ipv4_prefix_len, broadcast), 0);
|
||||
|
||||
ip_a_show_dev([this, &broadcast](std::vector<std::string>& v, const std::string& out, bool& called) {
|
||||
if (v[0] == "inet")
|
||||
{
|
||||
called = true;
|
||||
ASSERT_EQ(v[1], addr4 + "/" + std::to_string(ipv4_prefix_len)) << out;
|
||||
ASSERT_EQ(v[3], broadcast.to_string()) << out;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(SitnlTest, TestAddrAdd6)
|
||||
{
|
||||
ASSERT_EQ(SITNL::net_addr_add(dev, IPv6::Addr::from_string(addr6), ipv6_prefix_len), 0);
|
||||
|
||||
ip_a_show_dev([this](std::vector<std::string>& v, const std::string& out, bool& called) {
|
||||
if (v[0] == "inet6")
|
||||
{
|
||||
called = true;
|
||||
ASSERT_EQ(v[1], addr6 + "/" + std::to_string(ipv6_prefix_len)) << out;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(SitnlTest, TestSetMTU)
|
||||
{
|
||||
ASSERT_EQ(SITNL::net_iface_mtu_set(dev, mtu), 0);
|
||||
|
||||
ip_a_show_dev([this](std::vector<std::string>& v, const std::string& out, bool& called) {
|
||||
if (dev + ":" == v[1])
|
||||
{
|
||||
called = true;
|
||||
ASSERT_EQ(v[4], std::to_string(mtu)) << out;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(SitnlTest, TestAddRoute4)
|
||||
{
|
||||
// add address
|
||||
auto broadcast = IPv4::Addr::from_string(addr4) | ~IPv4::Addr::netmask_from_prefix_len(ipv4_prefix_len);
|
||||
ASSERT_EQ(SITNL::net_addr_add(dev, IPv4::Addr::from_string(addr4), ipv4_prefix_len, broadcast), 0);
|
||||
|
||||
// up interface
|
||||
ASSERT_EQ(SITNL::net_iface_up(dev, true), 0);
|
||||
|
||||
// add route
|
||||
ASSERT_EQ(SITNL::net_route_add(IP::Route4(route4), IPv4::Addr::from_string(gw4), dev, 0, 0), 0);
|
||||
|
||||
std::string dst{"10.110.0.100"};
|
||||
|
||||
ip_route_get(dst, [this, &dst](std::vector<std::string>& v, const std::string& out, bool& called) {
|
||||
if (v[0] == dst)
|
||||
{
|
||||
called = true;
|
||||
v.resize(7);
|
||||
auto expected = std::vector<std::string>{dst, "via", gw4, "dev", dev, "src", addr4};
|
||||
ASSERT_EQ(v, expected) << out;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(SitnlTest, TestAddRoute6)
|
||||
{
|
||||
// add address
|
||||
ASSERT_EQ(SITNL::net_addr_add(dev, IPv6::Addr::from_string(addr6), ipv6_prefix_len), 0);
|
||||
|
||||
// up interface
|
||||
ASSERT_EQ(SITNL::net_iface_up(dev, true), 0);
|
||||
|
||||
// add route
|
||||
ASSERT_EQ(SITNL::net_route_add(IP::Route6(route6), IPv6::Addr::from_string(gw6), dev, 0, 0), 0);
|
||||
|
||||
std::string dst{"fe80:20c3:cccc:dddd:cccc:dddd:eeee:ffff"};
|
||||
|
||||
ip_route_get(dst, [this, &dst](std::vector<std::string> &v1, const std::string &out, bool &called) {
|
||||
if (v1[0] == dst)
|
||||
{
|
||||
called = true;
|
||||
v1.resize(7);
|
||||
// iptools 4.15 (Ubuntu 18)
|
||||
auto expected1 = std::vector<std::string>{dst, "from", "::", "via", gw6, "dev", dev};
|
||||
auto ok1 = (v1 == expected1);
|
||||
|
||||
auto v2 = v1;
|
||||
v2.resize(5);
|
||||
// iptools 4.11 (CentOS 7)
|
||||
auto expected2 = std::vector<std::string>{dst, "via", gw6, "dev", dev};
|
||||
auto ok2 = (v2 == expected2);
|
||||
|
||||
if (!ok1 && !ok2)
|
||||
{
|
||||
// this is just a way to print actual value and all expected values
|
||||
EXPECT_EQ(v1, expected1);
|
||||
EXPECT_EQ(v2, expected2);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(SitnlTest, TestBestGw4)
|
||||
{
|
||||
// add address
|
||||
auto broadcast = IPv4::Addr::from_string(addr4) | ~IPv4::Addr::netmask_from_prefix_len(ipv4_prefix_len);
|
||||
ASSERT_EQ(SITNL::net_addr_add(dev, IPv4::Addr::from_string(addr4), ipv4_prefix_len, broadcast), 0);
|
||||
|
||||
// up interface
|
||||
ASSERT_EQ(SITNL::net_iface_up(dev, true), 0);
|
||||
|
||||
// add routes
|
||||
|
||||
// shortest prefix
|
||||
ASSERT_EQ(SITNL::net_route_add(IP::Route4("10.0.0.0/8"), IPv4::Addr::from_string("10.10.10.10"), dev, 0, 0), 0);
|
||||
// longest prefix, lowest metric
|
||||
ASSERT_EQ(SITNL::net_route_add(IP::Route4("10.10.10.0/24"), IPv4::Addr::from_string("10.10.10.13"), dev, 0, 0), 0);
|
||||
// short prefix
|
||||
ASSERT_EQ(SITNL::net_route_add(IP::Route4("10.10.0.0/16"), IPv4::Addr::from_string("10.10.10.11"), dev, 0, 0), 0);
|
||||
// longest prefix, highest metric
|
||||
ASSERT_EQ(SITNL::net_route_add(IP::Route4("10.10.10.0/24"), IPv4::Addr::from_string("10.10.10.12"), dev, 0, 10), 0);
|
||||
|
||||
IPv4::Addr best_gw;
|
||||
std::string best_iface;
|
||||
ASSERT_EQ(SITNL::net_route_best_gw(IP::Route4("10.10.10.1/32"), best_gw, best_iface), 0);
|
||||
|
||||
// we should get a gateway with longest prefix and lowest metric
|
||||
|
||||
ASSERT_EQ(best_gw.to_string(), "10.10.10.13");
|
||||
ASSERT_EQ(best_iface, dev);
|
||||
}
|
||||
|
||||
TEST_F(SitnlTest, TestBestGw4FilterIface)
|
||||
{
|
||||
// add addresses
|
||||
auto broadcast = IPv4::Addr::from_string(addr4) | ~IPv4::Addr::netmask_from_prefix_len(ipv4_prefix_len);
|
||||
ASSERT_EQ(SITNL::net_addr_add(dev, IPv4::Addr::from_string(addr4), ipv4_prefix_len, broadcast), 0);
|
||||
|
||||
broadcast = IPv4::Addr::from_string("10.20.0.2") | ~IPv4::Addr::netmask_from_prefix_len(ipv4_prefix_len);
|
||||
ASSERT_EQ(SITNL::net_addr_add(dev2, IPv4::Addr::from_string("10.20.0.2"), ipv4_prefix_len, broadcast), 0);
|
||||
|
||||
// up interfaces
|
||||
SITNL::net_iface_up(dev, true);
|
||||
SITNL::net_iface_up(dev2, true);
|
||||
|
||||
// add routes
|
||||
ASSERT_EQ(SITNL::net_route_add(IP::Route4("10.11.0.0/16"), IPv4::Addr::from_string("10.10.0.1"), dev, 0, 0), 0);
|
||||
ASSERT_EQ(SITNL::net_route_add(IP::Route4("10.11.12.0/24"), IPv4::Addr::from_string("10.20.0.1"), dev2, 0, 0), 0);
|
||||
|
||||
IPv4::Addr best_gw;
|
||||
std::string best_iface;
|
||||
|
||||
// filter out gateway with longest prefix route
|
||||
SITNL::net_route_best_gw(IP::Route4("10.11.12.13/32"), best_gw, best_iface, dev2);
|
||||
|
||||
ASSERT_EQ(best_gw.to_string(), "10.10.0.1");
|
||||
ASSERT_EQ(best_iface, dev);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="ReleaseOpenSSL|x64">
|
||||
<Configuration>ReleaseOpenSSL</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{18446924-20CC-4EB7-B639-A76C1422E5C2}</ProjectGuid>
|
||||
<RootNamespace>unittests</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOpenSSL|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOpenSSL|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 />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>TurnOffAllWarnings</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>false</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(OVPN3_ROOT)\deps\amd64\mbedtls\include;$(OVPN3_ROOT)\deps\amd64\lz4\lib;$(GTEST_ROOT)\googletest\include;$(OVPN3_ROOT)\core;$(OVPN3_ROOT)\deps\amd64\asio\asio\include;$(OVPN3_ROOT)\deps\amd64\tap-windows\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NOMINMAX;_WIN32_WINNT=0x0600;USE_ASIO;ASIO_STANDALONE;USE_MBEDTLS;HAVE_LZ4;OPENVPN_FORCE_TUN_NULL;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>lz4.lib;mbedtls.lib;Iphlpapi.lib;gtest.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(OVPN3_ROOT)\deps\amd64\mbedtls\library;$(GTEST_ROOT)\googlemock\gtest\Debug\;%(AdditionalLibraryDirectories);$(OVPN3_ROOT)\deps\amd64\lz4\lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>TurnOffAllWarnings</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>false</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(OVPN3_ROOT)\deps\amd64\mbedtls\include;$(OVPN3_ROOT)\deps\amd64\lz4\lib;$(GTEST_ROOT)\googletest\include;$(OVPN3_ROOT)\core;$(OVPN3_ROOT)\deps\amd64\asio\asio\include;$(OVPN3_ROOT)\deps\amd64\tap-windows\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NOMINMAX;_WIN32_WINNT=0x0600;USE_ASIO;ASIO_STANDALONE;USE_MBEDTLS;HAVE_LZ4;OPENVPN_FORCE_TUN_NULL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>lz4.lib;mbedtls.lib;Iphlpapi.lib;gtest.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(OVPN3_ROOT)\deps\amd64\mbedtls\library;$(GTEST_ROOT)\googlemock\gtest\Release\;%(AdditionalLibraryDirectories);$(OVPN3_ROOT)\deps\amd64\lz4\lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOpenSSL|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>TurnOffAllWarnings</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>false</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(OVPN3_ROOT)\deps\amd64\mbedtls\include;$(OVPN3_ROOT)\deps\amd64\lz4\lib;$(GTEST_ROOT)\googletest\include;$(OVPN3_ROOT)\core;$(OVPN3_ROOT)\deps\amd64\asio\asio\include;$(OVPN3_ROOT)\deps\amd64\tap-windows\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NOMINMAX;_WIN32_WINNT=0x0600;USE_ASIO;ASIO_STANDALONE;USE_MBEDTLS;HAVE_LZ4;OPENVPN_FORCE_TUN_NULL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>lz4.lib;mbedtls.lib;Iphlpapi.lib;gtest.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(OVPN3_ROOT)\deps\amd64\mbedtls\library;$(GTEST_ROOT)\googlemock\gtest\Release\;%(AdditionalLibraryDirectories);$(OVPN3_ROOT)\deps\amd64\lz4\lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="test_log.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="test_log.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user