2015-01-21 21:58:35 +01:00
|
|
|
/*******************************************************************************
|
2015-10-22 00:25:12 +02:00
|
|
|
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
2015-01-21 21:58:35 +01:00
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* MINRES Technologies GmbH - initial API and implementation
|
|
|
|
*******************************************************************************/
|
2015-01-06 17:14:16 +01:00
|
|
|
package com.minres.scviewer.database.test;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
import java.io.File;
|
2018-11-03 17:49:40 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.NavigableMap;
|
2015-01-06 17:14:16 +01:00
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2018-11-03 17:49:40 +01:00
|
|
|
import com.minres.scviewer.database.AssociationType;
|
|
|
|
import com.minres.scviewer.database.DataType;
|
2020-11-28 10:22:22 +01:00
|
|
|
import com.minres.scviewer.database.EventKind;
|
|
|
|
import com.minres.scviewer.database.IEvent;
|
2018-11-03 17:49:40 +01:00
|
|
|
import com.minres.scviewer.database.IWaveform;
|
2015-01-06 17:14:16 +01:00
|
|
|
import com.minres.scviewer.database.IWaveformDb;
|
2015-10-24 23:15:07 +02:00
|
|
|
import com.minres.scviewer.database.IWaveformDbFactory;
|
2020-11-28 14:47:43 +01:00
|
|
|
import com.minres.scviewer.database.tx.ITx;
|
|
|
|
import com.minres.scviewer.database.tx.ITxAttribute;
|
|
|
|
import com.minres.scviewer.database.tx.ITxEvent;
|
2015-01-06 17:14:16 +01:00
|
|
|
|
|
|
|
public class DatabaseServicesTest {
|
|
|
|
|
2015-10-24 23:15:07 +02:00
|
|
|
|
|
|
|
private static IWaveformDbFactory waveformDbFactory;
|
|
|
|
|
|
|
|
private IWaveformDb waveformDb;
|
|
|
|
|
|
|
|
public synchronized void setFactory(IWaveformDbFactory service) {
|
|
|
|
waveformDbFactory = service;
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void unsetFactory(IWaveformDbFactory service) {
|
|
|
|
if (waveformDbFactory == service) {
|
|
|
|
waveformDbFactory = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-06 17:14:16 +01:00
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
2015-10-24 23:15:07 +02:00
|
|
|
waveformDb=waveformDbFactory.getDatabase();
|
|
|
|
}
|
2015-01-06 17:14:16 +01:00
|
|
|
|
|
|
|
@After
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2015-01-10 00:23:46 +01:00
|
|
|
public void testVCD() throws Exception {
|
2015-01-06 17:14:16 +01:00
|
|
|
File f = new File("inputs/my_db.vcd").getAbsoluteFile();
|
|
|
|
assertTrue(f.exists());
|
2015-10-24 23:15:07 +02:00
|
|
|
waveformDb.load(f);
|
|
|
|
assertNotNull(waveformDb);
|
2018-11-05 18:21:54 +01:00
|
|
|
List<IWaveform> waves= waveformDb.getAllWaves();
|
|
|
|
assertEquals(14, waves.size());
|
2015-10-24 23:15:07 +02:00
|
|
|
assertEquals(2, waveformDb.getChildNodes().size());
|
2018-11-05 18:21:54 +01:00
|
|
|
IWaveform bus_data_wave = waves.get(0);
|
2020-11-28 10:22:22 +01:00
|
|
|
Entry<Long, IEvent[]> bus_data_entry = bus_data_wave.getEvents().floorEntry(1400000000L);
|
|
|
|
assertTrue("01111000".equals(bus_data_entry.getValue()[0].toString()));
|
2018-11-05 18:21:54 +01:00
|
|
|
IWaveform rw_wave = waves.get(2);
|
2020-11-28 10:22:22 +01:00
|
|
|
Entry<Long, IEvent[]> rw_entry = rw_wave.getEvents().floorEntry(2360000000L);
|
|
|
|
assertTrue("1".equals(rw_entry.getValue()[0].toString()));
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2015-01-10 00:23:46 +01:00
|
|
|
public void testTxSQLite() throws Exception {
|
2018-11-03 17:49:40 +01:00
|
|
|
File f = new File("inputs/my_sqldb.txdb").getAbsoluteFile();
|
2015-01-06 17:14:16 +01:00
|
|
|
assertTrue(f.exists());
|
2015-10-24 23:15:07 +02:00
|
|
|
waveformDb.load(f);
|
|
|
|
assertNotNull(waveformDb);
|
|
|
|
assertEquals(3, waveformDb.getAllWaves().size());
|
|
|
|
assertEquals(1, waveformDb.getChildNodes().size());
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2015-01-10 00:23:46 +01:00
|
|
|
public void testTxText() throws Exception {
|
2015-01-06 17:14:16 +01:00
|
|
|
File f = new File("inputs/my_db.txlog").getAbsoluteFile();
|
|
|
|
assertTrue(f.exists());
|
2015-10-24 23:15:07 +02:00
|
|
|
waveformDb.load(f);
|
|
|
|
assertNotNull(waveformDb);
|
2021-01-03 14:16:56 +01:00
|
|
|
List<IWaveform> waveforms = waveformDb.getAllWaves();
|
|
|
|
assertEquals(3, waveforms.size());
|
2015-10-24 23:15:07 +02:00
|
|
|
assertEquals(1, waveformDb.getChildNodes().size());
|
2021-01-03 14:16:56 +01:00
|
|
|
for(IWaveform w:waveforms) {
|
|
|
|
if(w.getId().equals(1l)) {
|
|
|
|
assertEquals(2, w.getWidth());
|
|
|
|
} else if(w.getId().equals(2l)) {
|
|
|
|
assertEquals(1, w.getWidth());
|
|
|
|
} else if(w.getId().equals(3l)) {
|
|
|
|
assertEquals(1, w.getWidth());
|
|
|
|
}
|
|
|
|
}
|
2015-01-06 17:14:16 +01:00
|
|
|
}
|
|
|
|
|
2020-03-11 07:37:14 +01:00
|
|
|
@Test
|
|
|
|
public void testTxTextTruncated() throws Exception {
|
|
|
|
File f = new File("inputs/my_db_truncated.txlog").getAbsoluteFile();
|
|
|
|
assertTrue(f.exists());
|
|
|
|
waveformDb.load(f);
|
|
|
|
assertNotNull(waveformDb);
|
|
|
|
assertEquals(3, waveformDb.getAllWaves().size());
|
|
|
|
assertEquals(1, waveformDb.getChildNodes().size());
|
|
|
|
}
|
|
|
|
|
2018-11-06 08:24:26 +01:00
|
|
|
//@Test
|
2018-11-03 17:49:40 +01:00
|
|
|
public void testTxLDb() throws Exception {
|
|
|
|
File f = new File("inputs/my_ldb.txldb").getAbsoluteFile();
|
|
|
|
assertTrue(f.exists());
|
|
|
|
waveformDb.load(f);
|
|
|
|
assertNotNull(waveformDb);
|
|
|
|
assertEquals(1, waveformDb.getChildNodes().size());
|
2018-11-05 18:21:54 +01:00
|
|
|
List<IWaveform> waves = waveformDb.getAllWaves();
|
2018-11-03 17:49:40 +01:00
|
|
|
assertEquals(3, waves.size());
|
2020-11-28 10:22:22 +01:00
|
|
|
IWaveform stream = waves.get(0);
|
|
|
|
NavigableMap<Long, IEvent[]> eventsList = stream.getEvents();
|
2018-11-05 18:21:54 +01:00
|
|
|
assertEquals(27, eventsList.size());
|
2020-11-28 10:22:22 +01:00
|
|
|
Entry<Long, IEvent[]> eventEntry = eventsList.firstEntry();
|
2018-11-05 18:21:54 +01:00
|
|
|
assertEquals(100000000L, (long) eventEntry.getKey());
|
2020-11-28 10:22:22 +01:00
|
|
|
IEvent[] events = eventEntry.getValue();
|
|
|
|
assertEquals(1, events.length);
|
|
|
|
IEvent event = events[0];
|
|
|
|
assertEquals(EventKind.BEGIN, event.getKind());
|
|
|
|
assertTrue(event instanceof ITxEvent);
|
|
|
|
ITx tx = ((ITxEvent)event).getTransaction();
|
2018-11-03 17:49:40 +01:00
|
|
|
assertEquals(3L, (long) tx.getId());
|
|
|
|
List<ITxAttribute> attrs = tx.getAttributes();
|
|
|
|
assertEquals(1, attrs.size());
|
|
|
|
ITxAttribute attr = attrs.get(0);
|
|
|
|
assertEquals("data", attr.getName());
|
|
|
|
assertEquals(DataType.UNSIGNED, attr.getDataType());
|
|
|
|
assertEquals(AssociationType.END, attr.getType());
|
|
|
|
assertTrue(attr.getValue() instanceof Integer);
|
|
|
|
assertEquals(0, (int) attr.getValue());
|
|
|
|
}
|
|
|
|
|
2018-07-14 11:42:55 +02:00
|
|
|
@Test
|
|
|
|
public void testHierarchicalVCD() throws Exception {
|
|
|
|
File f = new File("inputs/simple_system.vcd").getAbsoluteFile();
|
|
|
|
assertTrue(f.exists());
|
|
|
|
waveformDb.load(f);
|
|
|
|
assertNotNull(waveformDb);
|
2018-10-11 11:20:36 +02:00
|
|
|
assertEquals(779, waveformDb.getAllWaves().size());
|
2018-07-16 13:17:58 +02:00
|
|
|
assertEquals(1, waveformDb.getChildNodes().size());
|
2018-07-14 11:42:55 +02:00
|
|
|
}
|
|
|
|
|
2015-01-06 17:14:16 +01:00
|
|
|
|
|
|
|
}
|