Changeset 13980


Ignore:
Timestamp:
Nov 7, 2019 10:47:44 AM (7 days ago)
Author:
mjohnsson
Message:

#5870 Fixed All Checksum related mj-2630

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG.txt

    r13968 r13980  
    11================= Unreleased ==================
     2# Change ; Minor ; Compiler; #5870
     3Debug log now contains checksums of all generated c-files.
     4
    25# Fixed ; Minor ; Compiler; #5864
    36Fixed bug where partial variability propagation lead to unbalanced equation systems.
  • trunk/Compiler/ModelicaCompiler/src/jastadd/ModelicaCompiler.jrag

    r13968 r13980  
    13701370        fc.guidManager().setSourceFile(new File(outDir, "modelDescription.xml"));
    13711371        fc.guidManager().processDependentFiles();
    1372        
     1372        log.debug("Checksum for generated files");
     1373        fc.guidManager().writeFileMD5(log);
    13731374        log.debug("... code generated.");
    13741375        ASTNode.endStep("generateCode()");
     
    21772178            SplitFilesCodeStream stream = new SplitFilesCodeStream(outFile, debugGen, header);
    21782179            gen.generate(tmpl, stream, header);
     2180           
    21792181            for (File file : stream.files()) {
    21802182                log.debug("Generated file '" + file + "'.");
    21812183                if (fc != null) {
     2184                    try {
     2185                        fc.guidManager().createFileMD5(new FileReader(file), file.getName(), log);
     2186                    } catch (FileNotFoundException e) {
     2187                        throw e;
     2188                    } catch (IOException e) {
     2189                        // Should not happen
     2190                    }
    21822191                    fc.guidManager().addDependentFile(file);
    21832192                }
  • trunk/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/GUIDManager.java

    r13968 r13980  
    55import java.io.ByteArrayOutputStream;
    66import java.io.File;
     7import java.io.FileReader;
     8import java.io.FileWriter;
    79import java.io.IOException;
    810import java.io.InputStream;
     
    1012import java.io.OutputStream;
    1113import java.io.PrintWriter;
     14import java.io.Reader;
    1215import java.math.BigInteger;
    1316import java.nio.charset.Charset;
     
    2124import java.util.List;
    2225
     26import org.jmodelica.util.logging.ModelicaLogger;
     27
    2328public class GUIDManager {
    2429
     
    8590    public void addDependentString(String input, ByteArrayOutputStream output) {
    8691        dependentFiles.add(new StringOpenable(input, output));
     92    }
     93   
     94    public ArrayList<String> filesMd5 = new ArrayList<String>();
     95
     96    public void writeFileMD5(ModelicaLogger log) {
     97        for (String fileMd5 : filesMd5) {
     98            log.debug(fileMd5);
     99        }
     100    }
     101
     102    public void createFileMD5(Reader file, String fileName, ModelicaLogger log) throws IOException {
     103        MessageDigest md5;
     104        try {
     105            md5 = MessageDigest.getInstance("MD5");
     106        } catch (NoSuchAlgorithmException e) {
     107            return;
     108        }
     109
     110        try (final BufferedReader reader = new BufferedReader(file)) {
     111            String line = reader.readLine();
     112            while (line != null) {
     113                // A naive implementation that is expected to create a digest different from what a command
     114                // line tool would create. No lines breaks are included in the digest, and no
     115                // character encodings are specified.
     116                md5.update(line.getBytes(Charset.forName("UTF-8")));
     117                line = reader.readLine();
     118            }
     119        }
     120       
     121        String Value = new BigInteger(1,md5.digest()).toString(16);
     122        filesMd5.add("Generated file "+ fileName + " with checksum " + Value);
    87123    }
    88124
  • trunk/Compiler/ModelicaFrontEnd/test/junit/org/jmodelica/test/common/GUIDManagerTest.java

    r13968 r13980  
    33import static org.junit.Assert.assertEquals;
    44import static org.junit.Assert.assertFalse;
     5import static org.junit.Assert.assertNull;
    56import static org.junit.Assert.assertTrue;
    67
    78import java.io.ByteArrayOutputStream;
     9import java.io.FileReader;
     10import java.io.IOException;
     11import java.io.StringReader;
    812
    913import org.jmodelica.common.GUIDManager;
     14import org.jmodelica.util.logging.Level;
    1015import org.junit.Before;
    1116import org.junit.Test;
     
    117122        assertEquals(ignoreWhitespace(expected), ignoreWhitespace(actual));
    118123    }
     124   
     125    @Test
     126    public void checksumOfFilesOnlyWrittenAtDebug() {
     127        TestLogger log = new TestLogger(Level.VERBOSE);
     128        guidManager.filesMd5.add("DummyHash");
     129        guidManager.writeFileMD5(log);
     130        assertNull(log.next());
     131       
     132        log = new TestLogger(Level.DEBUG);
     133        guidManager.filesMd5.add("DummyHash");
     134        guidManager.writeFileMD5(log);
     135        assertEquals("DEBUG: DummyHash", log.next());
     136    }
    119137
     138    @Test
     139    public void checksumFiles() throws IOException {
     140        TestLogger log = new TestLogger(Level.VERBOSE);
     141        String dummyFile = "This is a dummy c-file /n c-stuff";
     142        StringReader reader = new StringReader(dummyFile);
     143        guidManager.createFileMD5(reader, "dummyfile.c", log);
     144        guidManager.writeFileMD5(log);
     145        assertNull(log.next());
     146       
     147        reader = new StringReader(dummyFile);
     148        log = new TestLogger(Level.DEBUG);
     149        guidManager.createFileMD5(reader, "dummyfile.c", log);
     150        guidManager.writeFileMD5(log);
     151        assertEquals("DEBUG: Generated file dummyfile.c with checksum fcde3f483c06e4a10bc5b28ec56214f8", log.next());
     152    }
    120153}
Note: See TracChangeset for help on using the changeset viewer.